From e6d03cdc40c2c178ecbf442bf3f210228fe8eb20 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Tue, 8 Mar 2022 18:44:50 +0200 Subject: [PATCH] redirect uri promise checks --- src/controller/authorization.ts | 6 ++++-- src/model/model.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/controller/authorization.ts b/src/controller/authorization.ts index 4f5c224..7129f99 100644 --- a/src/controller/authorization.ts +++ b/src/controller/authorization.ts @@ -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'); diff --git a/src/model/model.ts b/src/model/model.ts index e7c60ea..81511ab 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -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; /** * Check the redirect uri against a client */ - checkRedirectUri: (client: OAuth2Client, redirectUri: string) => boolean; + checkRedirectUri: ( + client: OAuth2Client, + redirectUri: string + ) => Promise; /** * Transform the scope into a string array of scopes