Matthias Kunnen 2019-05-14 00:21:38 +02:00 committed by Nathan Shively-Sanders
parent 32b5bf0bb7
commit b60d757ef4
2 changed files with 62 additions and 0 deletions

View File

@ -58,6 +58,62 @@ export interface ErrorHandlerOptions {
mode?: string;
}
export class OAuth2Error extends Error {
code: string;
status: number;
uri?: string;
/**
* @param code Defaults to *server_error*.
* @param status Defaults to 500.
*/
constructor(message?: string, code?: string, uri?: string, status?: number);
}
export type AuthorizationErrorCode = 'invalid_request'
| 'unauthorized_client'
| 'access_denied'
| 'unsupported_response_type'
| 'invalid_scope'
| 'temporarily_unavailable';
export class AuthorizationError extends OAuth2Error {
/**
* @param code The code sets the status unless status is present. Mapping:
* invalid_request = 400
* unauthorized_client = 403
* access_denied = 403
* unsupported_response_type = 501
* invalid_scope = 400
* temporarily_unavailable = 503
* Defaults to *server_error*.
* @param status Defaults to 500 if code is not specified.
*/
constructor(message?: string, code?: AuthorizationErrorCode | string, uri?: string, status?: number);
}
export type TokenErrorCode = 'invalid_request'
| 'invalid_client'
| 'invalid_grant'
| 'unauthorized_client'
| 'unsupported_grant_type'
| 'invalid_scope';
export class TokenError extends OAuth2Error {
/**
* @param code The code sets the status unless status is present. Mapping:
* invalid_request = 400
* invalid_client = 401
* invalid_grant = 403
* unauthorized_client = 403
* unsupported_grant_type = 501
* invalid_scope = 400
* Defaults to server_error.
* @param status Defaults to 500 if code is not specified.
*/
constructor(message?: string, code?: TokenErrorCode | string, uri?: string, status?: number);
}
export type MiddlewareFunction = (req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;
export type MiddlewareErrorFunction = (err: Error, req: MiddlewareRequest, res: ServerResponse, next: MiddlewareNextFunction) => void;

View File

@ -91,3 +91,9 @@ server.deserializeClient((id, done) => {
server.token();
server.errorHandler();
// );
// Test errors
const tokenError = new oauth2orize.TokenError('Incorrect token', 'invalid_grant');
const code: string = tokenError.code;
new oauth2orize.AuthorizationError('Incorrect token', 'access_denied');
new oauth2orize.OAuth2Error();