redirect uri promise checks

This commit is contained in:
Evert Prants 2022-03-08 18:44:50 +02:00
parent 8f5146d68f
commit e6d03cdc40
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 11 additions and 6 deletions

View File

@ -100,9 +100,11 @@ export const authorization = wrap(async (req, res) => {
}
// TODO: multiple redirect URI
if (!oauth2.model.client.getRedirectUri(client)) {
if (!(await oauth2.model.client.hasRedirectUri(client))) {
throw new UnsupportedResponseType('The client has not set a redirect uri');
} else if (!oauth2.model.client.checkRedirectUri(client, redirectUri)) {
} else if (
!(await oauth2.model.client.checkRedirectUri(client, redirectUri))
) {
throw new InvalidRequest('Wrong RedirectUri provided');
}
req.oauth2.logger.debug('redirect_uri check passed');

View File

@ -19,7 +19,7 @@ export interface OAuth2AccessToken {
user_id: string | number;
client_id: string | number;
scope: string;
expires_at: number;
expires_at: Date;
}
/**
@ -27,7 +27,7 @@ export interface OAuth2AccessToken {
*/
export interface OAuth2Code {
code: string;
expires_at: number;
expires_at: Date;
user_id: string | number;
client_id: string | number;
scope: string;
@ -140,12 +140,15 @@ export interface OAuth2ClientAdapter {
/**
* Get the redirect uri of a client
*/
getRedirectUri: (client: OAuth2Client) => string;
hasRedirectUri: (client: OAuth2Client) => Promise<boolean>;
/**
* Check the redirect uri against a client
*/
checkRedirectUri: (client: OAuth2Client, redirectUri: string) => boolean;
checkRedirectUri: (
client: OAuth2Client,
redirectUri: string
) => Promise<boolean>;
/**
* Transform the scope into a string array of scopes