Skip to content

Removed callback support in typings file. #211

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

Merged
Merged
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
54 changes: 23 additions & 31 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ declare class OAuth2Server {
authenticate(
request: OAuth2Server.Request,
response: OAuth2Server.Response,
options?: OAuth2Server.AuthenticateOptions,
callback?: OAuth2Server.Callback<OAuth2Server.Token>
options?: OAuth2Server.AuthenticateOptions
): Promise<OAuth2Server.Token>;

/**
Expand All @@ -33,8 +32,7 @@ declare class OAuth2Server {
authorize(
request: OAuth2Server.Request,
response: OAuth2Server.Response,
options?: OAuth2Server.AuthorizeOptions,
callback?: OAuth2Server.Callback<OAuth2Server.AuthorizationCode>
options?: OAuth2Server.AuthorizeOptions
): Promise<OAuth2Server.AuthorizationCode>;

/**
Expand All @@ -43,8 +41,7 @@ declare class OAuth2Server {
token(
request: OAuth2Server.Request,
response: OAuth2Server.Response,
options?: OAuth2Server.TokenOptions,
callback?: OAuth2Server.Callback<OAuth2Server.Token>
options?: OAuth2Server.TokenOptions
): Promise<OAuth2Server.Token>;
}

Expand Down Expand Up @@ -238,11 +235,6 @@ declare namespace OAuth2Server {
extendedGrantTypes?: { [key: string]: typeof AbstractGrantType } | undefined;
}

/**
* Represents a generic callback structure for model callbacks
*/
type Callback<T> = (err?: any, result?: T) => void;

/**
* For returning falsey parameters in cases of failure
*/
Expand All @@ -253,53 +245,53 @@ declare namespace OAuth2Server {
* Invoked to generate a new access token.
*
*/
generateAccessToken?(client: Client, user: User, scope: string | string[], callback?: Callback<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, callback?: Callback<Client | Falsey>): Promise<Client | Falsey>;
getClient(clientId: string, clientSecret: string): 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, callback?: Callback<Token>): Promise<Token | Falsey>;
saveToken(token: Token, client: Client, user: User): Promise<Token | Falsey>;
}

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

/**
* Invoked during request authentication to check if the provided access token was authorized the requested scopes.
*
*/
verifyScope(token: Token, scope: string | string[], callback?: Callback<boolean>): Promise<boolean>;
verifyScope(token: Token, scope: string | string[]): Promise<boolean>;
}

interface AuthorizationCodeModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
*/
generateRefreshToken?(client: Client, user: User, scope: string | string[], callback?: Callback<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 | string[], callback?: Callback<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, callback?: Callback<AuthorizationCode>): Promise<AuthorizationCode | Falsey>;
getAuthorizationCode(authorizationCode: string): Promise<AuthorizationCode | Falsey>;

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

/**
* Invoked to revoke an authorization code.
*
*/
revokeAuthorizationCode(code: AuthorizationCode, callback?: Callback<boolean>): Promise<boolean>;
revokeAuthorizationCode(code: AuthorizationCode): Promise<boolean>;

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

/**
* Invoked to check if the provided `redirectUri` is valid for a particular `client`.
Expand All @@ -335,53 +327,53 @@ declare namespace OAuth2Server {
* Invoked to generate a new refresh token.
*
*/
generateRefreshToken?(client: Client, user: User, scope: string | string[], callback?: Callback<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, callback?: Callback<User | Falsey>): Promise<User | Falsey>;
getUser(username: string, password: string): 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 | string[], callback?: Callback<string | Falsey>): Promise<string | string[] | Falsey>;
validateScope?(user: User, client: Client, scope: string | string[]): Promise<string | string[] | Falsey>;
}

interface RefreshTokenModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
*/
generateRefreshToken?(client: Client, user: User, scope: string | string[], callback?: Callback<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, callback?: Callback<RefreshToken>): Promise<RefreshToken | Falsey>;
getRefreshToken(refreshToken: string): Promise<RefreshToken | Falsey>;

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

interface ClientCredentialsModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to retrieve the user associated with the specified client.
*
*/
getUserFromClient(client: Client, callback?: Callback<User | Falsey>): Promise<User | Falsey>;
getUserFromClient(client: Client): 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 | string[], callback?: Callback<string | Falsey>): Promise<string | string[] | Falsey>;
validateScope?(user: User, client: Client, scope: string | string[]): Promise<string | string[] | Falsey>;
}

interface ExtensionModel extends BaseModel, RequestAuthenticationModel {}
Expand Down