From 184879995c1fb1d1f4a8803246fd0ecc41166a4d Mon Sep 17 00:00:00 2001 From: rvitorsantos Date: Fri, 23 Nov 2018 11:38:27 -0200 Subject: [PATCH 1/2] Add typing for Abstract Grant Type * Add typing for Abstract Grant Type * Add parameter extendedGrantTypes in TokenModel interface --- types/oauth2-server/index.d.ts | 61 +++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/types/oauth2-server/index.d.ts b/types/oauth2-server/index.d.ts index 27a863051f..4d4715b41f 100644 --- a/types/oauth2-server/index.d.ts +++ b/types/oauth2-server/index.d.ts @@ -2,7 +2,8 @@ // Project: https://github.com/oauthjs/node-oauth2-server // Definitions by: Robbie Van Gorkom , // Charles Irick , -// Daniel Fischer +// Daniel Fischer , +// Vitor Santos // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -112,6 +113,59 @@ declare namespace OAuth2Server { redirect(url: string): void; } + abstract class AbstractGrantType { + + /** + * Instantiates AbstractGrantType using the supplied options. + * + */ + constructor(options: TokenOptions) + + /** + * Generate access token. Calls Model#generateAccessToken() if implemented. + * + */ + generateAccessToken(client: Client, user: User, scope: string | string[]): Promise; + + /** + * Generate refresh token. Calls + * + */ + generateRefreshToken(client: Client, user: User, scope: string | string[]): Promise; + + /** + * Get access token expiration date. + * + */ + getAccessTokenExpiresAt(): Date; + + /** + * Get refresh token expiration date. + * + */ + getRefreshTokenExpiresAt(): Date; + + /** + * Get scope from the request body. + * + */ + getScope(request: Request): string; + + /** + * Validate requested scope. Calls Model#validateScope() if implemented. + * + */ + validateScope(user: User, client: Client, scope: string | string[]): Promise; + + /** + * Retrieve info from the request and client and return token + * + */ + abstract handle(request: Request, client: Client): Promise; + + } + + interface ServerOptions extends AuthenticateOptions, AuthorizeOptions, TokenOptions { /** * Model object @@ -183,6 +237,11 @@ declare namespace OAuth2Server { * Always revoke the used refresh token and issue a new one for the refresh_token grant. */ alwaysIssueNewRefreshToken?: boolean; + + /** + * Additional supported grant types. + */ + extendedGrantTypes?: {[key: string]: typeof AbstractGrantType }; } /** From adad38a0d50d2e53925bab47a87d09b1b9e4506d Mon Sep 17 00:00:00 2001 From: Vitor Santos Date: Fri, 23 Nov 2018 13:16:16 -0200 Subject: [PATCH 2/2] Fixed lint errors and incomplete comment --- types/oauth2-server/index.d.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/types/oauth2-server/index.d.ts b/types/oauth2-server/index.d.ts index 4d4715b41f..a846c489a2 100644 --- a/types/oauth2-server/index.d.ts +++ b/types/oauth2-server/index.d.ts @@ -114,7 +114,6 @@ declare namespace OAuth2Server { } abstract class AbstractGrantType { - /** * Instantiates AbstractGrantType using the supplied options. * @@ -128,7 +127,7 @@ declare namespace OAuth2Server { generateAccessToken(client: Client, user: User, scope: string | string[]): Promise; /** - * Generate refresh token. Calls + * Generate refresh token. Calls Model#generateRefreshToken() if implemented. * */ generateRefreshToken(client: Client, user: User, scope: string | string[]): Promise; @@ -162,10 +161,8 @@ declare namespace OAuth2Server { * */ abstract handle(request: Request, client: Client): Promise; - } - interface ServerOptions extends AuthenticateOptions, AuthorizeOptions, TokenOptions { /** * Model object @@ -241,7 +238,7 @@ declare namespace OAuth2Server { /** * Additional supported grant types. */ - extendedGrantTypes?: {[key: string]: typeof AbstractGrantType }; + extendedGrantTypes?: { [key: string]: typeof AbstractGrantType }; } /**