fix(hapi-auth-jwt2): allow validate and verify to return directly (#25306)

This commit is contained in:
Simon Schick 2018-04-26 19:28:20 +02:00 committed by Wesley Wigham
parent 2f6852e993
commit b67b2df1d9
2 changed files with 17 additions and 6 deletions

View File

@ -32,7 +32,7 @@ server.register({
.then(() => {
const opts: hapiAuthJwt2.Options = {
key: 'NeverShareYourSecret',
async validate(decoded: { id: number }, request) {
async validate(decoded: { id: number }) {
return {
isValid: !!users[decoded.id],
};
@ -42,5 +42,14 @@ server.register({
issuer: 'test',
}
};
const opts2: hapiAuthJwt2.Options = {
key: 'NeverShareYourSecret2',
validate(decoded: { id: number }) {
return {
isValid: !!users[decoded.id],
};
}
};
server.auth.strategy('jwt', 'jwt', opts);
server.auth.strategy('jwt2', 'jwt', opts2);
});

View File

@ -39,6 +39,12 @@ declare namespace hapiAuthJwt2 {
};
}
interface ValidationResult {
isValid: boolean;
credentials?: any;
response?: ResponseObject;
}
/**
* Options passed to `hapi.auth.strategy` when this plugin is used
*/
@ -54,11 +60,7 @@ declare namespace hapiAuthJwt2 {
* @param decoded the *decoded* and *verified* JWT received from the client in *request.headers.authorization*
* @param request the original *request* received from the client
*/
validate(decoded: {}, request: Request, tk: ResponseToolkit): Promise<{
isValid: boolean;
credentials?: any;
response?: ResponseObject
}>;
validate(decoded: {}, request: Request, tk: ResponseToolkit): ValidationResult | Promise<ValidationResult>;
/**
* Settings to define how tokens are verified by the jsonwebtoken library