Skip to content

types: make model types support sync AND async methods #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,54 +245,54 @@ declare namespace OAuth2Server {
* Invoked to generate a new access token.
*
*/
generateAccessToken?(client: Client, user: User, scope: string[]): Promise<string>;
generateAccessToken?(client: Client, user: User, scope: string[]): string | Promise<string>;

/**
* Invoked to retrieve a client using a client id or a client id/client secret combination, depending on the grant type.
*
*/
getClient(clientId: string, clientSecret: string): Promise<Client | Falsey>;
getClient(clientId: string, clientSecret: string): Client | Falsey | Promise<Client | Falsey>;

/**
* Invoked to save an access token and optionally a refresh token, depending on the grant type.
*
*/
saveToken(token: Token, client: Client, user: User): Promise<Token | Falsey>;
saveToken(token: Token, client: Client, user: User): Token | Falsey | Promise<Token | Falsey>;
}

interface RequestAuthenticationModel {
/**
* Invoked to retrieve an existing access token previously saved through Model#saveToken().
*
*/
getAccessToken(accessToken: string): Promise<Token | Falsey>;
getAccessToken(accessToken: string): Token | Falsey | Promise<Token | Falsey>;

/**
* Invoked during request authentication to check if the provided access token was authorized the requested scopes.
* Optional, if a custom authenticateHandler is used or if there is no scope part of the request.
*
*/
verifyScope?(token: Token, scope: string[]): Promise<boolean>;
verifyScope?(token: Token, scope: string[]): boolean | Promise<boolean>;
}

interface AuthorizationCodeModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
*/
generateRefreshToken?(client: Client, user: User, scope: string[]): Promise<string>;
generateRefreshToken?(client: Client, user: User, scope: string[]): string | Promise<string>;

/**
* Invoked to generate a new authorization code.
*
*/
generateAuthorizationCode?(client: Client, user: User, scope: string[]): Promise<string>;
generateAuthorizationCode?(client: Client, user: User, scope: string[]): string | Promise<string>;

/**
* Invoked to retrieve an existing authorization code previously saved through Model#saveAuthorizationCode().
*
*/
getAuthorizationCode(authorizationCode: string): Promise<AuthorizationCode | Falsey>;
getAuthorizationCode(authorizationCode: string): AuthorizationCode | Falsey | Promise<AuthorizationCode | Falsey>;

/**
* Invoked to save an authorization code.
Expand All @@ -302,79 +302,79 @@ declare namespace OAuth2Server {
code: Pick<AuthorizationCode, 'authorizationCode' | 'expiresAt' | 'redirectUri' | 'scope' | 'codeChallenge' | 'codeChallengeMethod'>,
client: Client,
user: User
): Promise<AuthorizationCode | Falsey>;
): AuthorizationCode | Falsey | Promise<AuthorizationCode | Falsey>;

/**
* Invoked to revoke an authorization code.
*
*/
revokeAuthorizationCode(code: AuthorizationCode): Promise<boolean>;
revokeAuthorizationCode(code: AuthorizationCode): boolean | Promise<boolean>;

/**
* Invoked to check if the requested scope is valid for a particular client/user combination.
*
*/
validateScope?(user: User, client: Client, scope?: string[]): Promise<string[] | Falsey>;
validateScope?(user: User, client: Client, scope?: string[]): string[] | Falsey | Promise<string[] | Falsey>;

/**
* Invoked to check if the provided `redirectUri` is valid for a particular `client`.
*
*/
validateRedirectUri?(redirect_uri: string, client: Client): Promise<boolean>;
validateRedirectUri?(redirect_uri: string, client: Client): boolean | Promise<boolean>;
}

interface PasswordModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
*/
generateRefreshToken?(client: Client, user: User, scope: string[]): Promise<string>;
generateRefreshToken?(client: Client, user: User, scope: string[]): string | Promise<string>;

/**
* Invoked to retrieve a user using a username/password combination.
*
*/
getUser(username: string, password: string, client: Client): Promise<User | Falsey>;
getUser(username: string, password: string, client: Client): User | Falsey | Promise<User | Falsey>;

/**
* Invoked to check if the requested scope is valid for a particular client/user combination.
*
*/
validateScope?(user: User, client: Client, scope?: string[]): Promise<string[] | Falsey>;
validateScope?(user: User, client: Client, scope?: string[]): string[] | Falsey | Promise<string[] | Falsey>;
}

interface RefreshTokenModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
*/
generateRefreshToken?(client: Client, user: User, scope: string[]): Promise<string>;
generateRefreshToken?(client: Client, user: User, scope: string[]): string | Promise<string>;

/**
* Invoked to retrieve an existing refresh token previously saved through Model#saveToken().
*
*/
getRefreshToken(refreshToken: string): Promise<RefreshToken | Falsey>;
getRefreshToken(refreshToken: string): RefreshToken | Falsey | Promise<RefreshToken | Falsey>;

/**
* Invoked to revoke a refresh token.
*
*/
revokeToken(token: RefreshToken): Promise<boolean>;
revokeToken(token: RefreshToken): boolean | Promise<boolean>;
}

interface ClientCredentialsModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to retrieve the user associated with the specified client.
*
*/
getUserFromClient(client: Client): Promise<User | Falsey>;
getUserFromClient(client: Client): User | Falsey | Promise<User | Falsey>;

/**
* Invoked to check if the requested scope is valid for a particular client/user combination.
*
*/
validateScope?(user: User, client: Client, scope?: string[]): Promise<string[] | Falsey>;
validateScope?(user: User, client: Client, scope?: string[]): string[] | Falsey | Promise<string[] | Falsey>;
}

interface ExtensionModel extends BaseModel, RequestAuthenticationModel {}
Expand Down