From baeccd245e804f5fa82b9160aaaa368d98be0aae Mon Sep 17 00:00:00 2001 From: rafaelsouzaf Date: Fri, 8 Dec 2017 20:49:42 -0300 Subject: [PATCH] Add request.route.auth.access() method --- .../definitions/request/request-route.d.ts | 21 ++++++++++++++++++- .../hapi/v17/definitions/request/request.d.ts | 19 ++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/types/hapi/v17/definitions/request/request-route.d.ts b/types/hapi/v17/definitions/request/request-route.d.ts index 531b60f796..2917c00606 100644 --- a/types/hapi/v17/definitions/request/request-route.d.ts +++ b/types/hapi/v17/definitions/request/request-route.d.ts @@ -1,4 +1,4 @@ -import {RouteOptions, ServerRealm, Util} from "hapi"; +import {RouteOptions, ServerRealm, Util, Request} from "hapi"; /** * The request route information object, where: @@ -11,16 +11,35 @@ import {RouteOptions, ServerRealm, Util} from "hapi"; * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute) */ export interface RequestRoute { + /** the route HTTP method. */ method: Util.HTTP_METHODS_PARTIAL; + /** the route path. */ path: string; + /** the route vhost option if configured. */ vhost?: string | string[]; + /** the active realm associated with the route.*/ realm: ServerRealm; + /** the route options object with all defaults applied. */ settings: RouteOptions; + /** the route internal normalized string representing the normalized path. */ fingerprint: string; + + auth: { + /** + * Validates a request against the route's authentication access configuration, where: + * @param request - the request object. + * @return Return value: true if the request would have passed the route's access requirements. + * Note that the route's authentication mode and strategies are ignored. The only match is made between the request.auth.credentials scope and entity information and the route access configuration. + * If the route uses dynamic scopes, the scopes are constructed against the request.query, request.params, request.payload, and request.auth.credentials which may or may not match between the route and the request's route. If this method is called using a request that has not been authenticated (yet or not at all), it will return false if the route requires any authentication. + * [See docs](https://hapijs.com/api/17.0.1#-requestrouteauthaccessrequest) + */ + access(request: Request): boolean; + } + } diff --git a/types/hapi/v17/definitions/request/request.d.ts b/types/hapi/v17/definitions/request/request.d.ts index 992a117b7d..7e7ec43e7c 100644 --- a/types/hapi/v17/definitions/request/request.d.ts +++ b/types/hapi/v17/definitions/request/request.d.ts @@ -160,14 +160,9 @@ export interface Request extends Podium { }; /** - * The request route information object, where: - * * method - the route HTTP method. - * * path - the route path. - * * vhost - the route vhost option if configured. - * * realm - the active realm associated with the route. - * * settings - the route options object with all defaults applied. - * * fingerprint - the route internal normalized string representing the normalized path. + * The request route information object and method * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute) + * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestrouteauthaccessrequest) */ readonly route: RequestRoute; @@ -209,16 +204,6 @@ export interface Request extends Podium { log(tags: string, data?: string | object | (() => string | object)): void; log(tags: string[], data?: string | object | (() => string | object)): void; - /** - * Validates a request against the route's authentication access configuration, where: - * @param request - the request object. - * @return Return value: true if the request would have passed the route's access requirements. - * Note that the route's authentication mode and strategies are ignored. The only match is made between the request.auth.credentials scope and entity information and the route access configuration. - * If the route uses dynamic scopes, the scopes are constructed against the request.query, request.params, request.payload, and request.auth.credentials which may or may not match between the route and the request's route. If this method is called using a request that has not been authenticated (yet or not at all), it will return false if the route requires any authentication. - * [See docs](https://hapijs.com/api/17.0.1#-requestrouteauthaccessrequest) - */ - // TODO how to implement it? It is a function inside route.auth! We have another "route" properti in this file. (The v16 doesn't have this option) - /** * Changes the request method before the router begins processing the request where: * @param method - is the request HTTP method (e.g. 'GET').