From 044b4178f662e27b207c8ed5f3f915be2a6ca02e Mon Sep 17 00:00:00 2001 From: Connor Schlesiger Date: Thu, 27 Sep 2018 15:37:05 -0400 Subject: [PATCH] Allow more Falsey returns and allow scope string arrays * scopes can be string arrays * Models can return `Falsey` types * Revoke Token accepts `Token` or `RefreshToken` (should really only be `RefreshToken`, though) --- types/oauth2-server/index.d.ts | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/types/oauth2-server/index.d.ts b/types/oauth2-server/index.d.ts index 6c20aab221..27a863051f 100644 --- a/types/oauth2-server/index.d.ts +++ b/types/oauth2-server/index.d.ts @@ -123,7 +123,7 @@ declare namespace OAuth2Server { /** * The scope(s) to authenticate. */ - scope?: string; + scope?: string | string[]; /** * Set the X-Accepted-OAuth-Scopes HTTP header on response objects. @@ -200,7 +200,7 @@ declare namespace OAuth2Server { * Invoked to generate a new access token. * */ - generateAccessToken?(client: Client, user: User, scope: string, callback?: Callback): Promise; + generateAccessToken?(client: Client, user: User, scope: string | string[], callback?: Callback): Promise; /** * Invoked to retrieve a client using a client id or a client id/client secret combination, depending on the grant type. @@ -212,7 +212,7 @@ declare namespace OAuth2Server { * Invoked to save an access token and optionally a refresh token, depending on the grant type. * */ - saveToken(token: Token, client: Client, user: User, callback?: Callback): Promise; + saveToken(token: Token, client: Client, user: User, callback?: Callback): Promise; } interface RequestAuthenticationModel { @@ -220,13 +220,13 @@ declare namespace OAuth2Server { * Invoked to retrieve an existing access token previously saved through Model#saveToken(). * */ - getAccessToken(accessToken: string, callback?: Callback): Promise; + getAccessToken(accessToken: string, callback?: Callback): Promise; /** * Invoked during request authentication to check if the provided access token was authorized the requested scopes. * */ - verifyScope(token: Token, scope: string, callback?: Callback): Promise; + verifyScope(token: Token, scope: string | string[], callback?: Callback): Promise; } interface AuthorizationCodeModel extends BaseModel, RequestAuthenticationModel { @@ -234,25 +234,25 @@ declare namespace OAuth2Server { * Invoked to generate a new refresh token. * */ - generateRefreshToken?(client: Client, user: User, scope: string, callback?: Callback): Promise; + generateRefreshToken?(client: Client, user: User, scope: string | string[], callback?: Callback): Promise; /** * Invoked to generate a new authorization code. * */ - generateAuthorizationCode?(client: Client, user: User, scope: string, callback?: Callback): Promise; + generateAuthorizationCode?(client: Client, user: User, scope: string | string[], callback?: Callback): Promise; /** * Invoked to retrieve an existing authorization code previously saved through Model#saveAuthorizationCode(). * */ - getAuthorizationCode(authorizationCode: string, callback?: Callback): Promise; + getAuthorizationCode(authorizationCode: string, callback?: Callback): Promise; /** * Invoked to save an authorization code. * */ - saveAuthorizationCode(code: AuthorizationCode, client: Client, user: User, callback?: Callback): Promise; + saveAuthorizationCode(code: AuthorizationCode, client: Client, user: User, callback?: Callback): Promise; /** * Invoked to revoke an authorization code. @@ -264,7 +264,7 @@ declare namespace OAuth2Server { * Invoked to check if the requested scope is valid for a particular client/user combination. * */ - validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; + validateScope?(user: User, client: Client, scope: string | string[], callback?: Callback): Promise; } interface PasswordModel extends BaseModel, RequestAuthenticationModel { @@ -272,7 +272,7 @@ declare namespace OAuth2Server { * Invoked to generate a new refresh token. * */ - generateRefreshToken?(client: Client, user: User, scope: string, callback?: Callback): Promise; + generateRefreshToken?(client: Client, user: User, scope: string | string[], callback?: Callback): Promise; /** * Invoked to retrieve a user using a username/password combination. @@ -284,7 +284,7 @@ declare namespace OAuth2Server { * Invoked to check if the requested scope is valid for a particular client/user combination. * */ - validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; + validateScope?(user: User, client: Client, scope: string | string[], callback?: Callback): Promise; } interface RefreshTokenModel extends BaseModel, RequestAuthenticationModel { @@ -292,19 +292,19 @@ declare namespace OAuth2Server { * Invoked to generate a new refresh token. * */ - generateRefreshToken?(client: Client, user: User, scope: string, callback?: Callback): Promise; + generateRefreshToken?(client: Client, user: User, scope: string | string[], callback?: Callback): Promise; /** * Invoked to retrieve an existing refresh token previously saved through Model#saveToken(). * */ - getRefreshToken(refreshToken: string, callback?: Callback): Promise; + getRefreshToken(refreshToken: string, callback?: Callback): Promise; /** * Invoked to revoke a refresh token. * */ - revokeToken(token: Token, callback?: Callback): Promise; + revokeToken(token: RefreshToken | Token, callback?: Callback): Promise; } interface ClientCredentialsModel extends BaseModel, RequestAuthenticationModel { @@ -318,7 +318,7 @@ declare namespace OAuth2Server { * Invoked to check if the requested scope is valid for a particular client/user combination. * */ - validateScope?(user: User, client: Client, scope: string, callback?: Callback): Promise; + validateScope?(user: User, client: Client, scope: string | string[], callback?: Callback): Promise; } interface ExtensionModel extends BaseModel, RequestAuthenticationModel {} @@ -336,8 +336,8 @@ declare namespace OAuth2Server { */ interface Client { id: string; - redirectUris?: string[]; - grants: string[]; + redirectUris?: string | string[]; + grants: string | string[]; accessTokenLifetime?: number; refreshTokenLifetime?: number; [key: string]: any; @@ -350,7 +350,7 @@ declare namespace OAuth2Server { authorizationCode: string; expiresAt: Date; redirectUri: string; - scope?: string; + scope?: string | string[]; client: Client; user: User; [key: string]: any; @@ -364,7 +364,7 @@ declare namespace OAuth2Server { accessTokenExpiresAt?: Date; refreshToken?: string; refreshTokenExpiresAt?: Date; - scope?: string; + scope?: string | string[]; client: Client; user: User; [key: string]: any; @@ -376,7 +376,7 @@ declare namespace OAuth2Server { interface RefreshToken { refreshToken: string; refreshTokenExpiresAt?: Date; - scope?: string; + scope?: string | string[]; client: Client; user: User; [key: string]: any;