From 0a5dfca310694e3bb8c11f15a6567a8fe6e852cf Mon Sep 17 00:00:00 2001 From: Peter Sabichay Phanouvong Date: Tue, 19 Mar 2024 10:47:51 +1100 Subject: [PATCH 1/3] feat: expose refreshTokens method --- lib/sdk/clients/browser/authcode-with-pkce.ts | 11 +++++++++++ lib/sdk/clients/server/authorization-code.ts | 11 +++++++++++ lib/sdk/oauth2-flows/AuthCodeAbstract.ts | 2 +- lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts | 2 +- lib/sdk/oauth2-flows/AuthorizationCode.ts | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/sdk/clients/browser/authcode-with-pkce.ts b/lib/sdk/clients/browser/authcode-with-pkce.ts index f586df6..e2c7bc7 100644 --- a/lib/sdk/clients/browser/authcode-with-pkce.ts +++ b/lib/sdk/clients/browser/authcode-with-pkce.ts @@ -267,6 +267,16 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => { const getToken = async (): Promise => { return await client.getToken(sessionManager); }; + + /** + * Method makes user of the `refreshTokens` method of the `AuthCodeWithPKCE` client + * to use the refresh token to get new tokens + * @param {SessionManager} sessionManager + * @returns {Promise} + */ + const refreshTokens = async (sessionManager: SessionManager): Promise => { + return await client.refreshTokens(sessionManager); + }; /** * Method extracts the provided feature flag from the access token in the @@ -314,6 +324,7 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => { createOrg, getClaim, getToken, + refreshTokens, register, getUser, getFlag, diff --git a/lib/sdk/clients/server/authorization-code.ts b/lib/sdk/clients/server/authorization-code.ts index b9a62de..fb0d7bb 100644 --- a/lib/sdk/clients/server/authorization-code.ts +++ b/lib/sdk/clients/server/authorization-code.ts @@ -133,6 +133,16 @@ const createAuthorizationCodeClient = ( return await client.getToken(sessionManager); }; + /** + * Method makes user of the `refreshTokens` method of the `AuthCodeAbstract` client + * to use the refresh token to get new tokens + * @param {SessionManager} sessionManager + * @returns {Promise} + */ + const refreshTokens = async (sessionManager: SessionManager): Promise => { + return await client.refreshTokens(sessionManager); + }; + /** * Method clears the current session and returns the logout URL, redirecting * to which will clear the user's session on the authorization server. @@ -151,6 +161,7 @@ const createAuthorizationCodeClient = ( getUserProfile, createOrg, getToken, + refreshTokens, register, getUser, logout, diff --git a/lib/sdk/oauth2-flows/AuthCodeAbstract.ts b/lib/sdk/oauth2-flows/AuthCodeAbstract.ts index 7e1881f..788d680 100644 --- a/lib/sdk/oauth2-flows/AuthCodeAbstract.ts +++ b/lib/sdk/oauth2-flows/AuthCodeAbstract.ts @@ -75,7 +75,7 @@ export abstract class AuthCodeAbstract { * @param {SessionManager} sessionManager * @returns {Promise} */ - protected abstract refreshTokens( + public abstract refreshTokens( sessionManager: SessionManager ): Promise; diff --git a/lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts b/lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts index bbac023..d161732 100644 --- a/lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts +++ b/lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts @@ -71,7 +71,7 @@ export class AuthCodeWithPKCE extends AuthCodeAbstract { * @param {SessionManager} sessionManager * @returns {Promise} */ - protected async refreshTokens( + public async refreshTokens( sessionManager: SessionManager ): Promise { const refreshToken = await utilities.getRefreshToken(sessionManager); diff --git a/lib/sdk/oauth2-flows/AuthorizationCode.ts b/lib/sdk/oauth2-flows/AuthorizationCode.ts index c594759..0424e18 100644 --- a/lib/sdk/oauth2-flows/AuthorizationCode.ts +++ b/lib/sdk/oauth2-flows/AuthorizationCode.ts @@ -56,7 +56,7 @@ export class AuthorizationCode extends AuthCodeAbstract { * @param {SessionManager} sessionManager * @returns {Promise} */ - protected async refreshTokens( + public async refreshTokens( sessionManager: SessionManager ): Promise { const refreshToken = await utilities.getRefreshToken(sessionManager); From 3f1801039657e6a569b39ad82e88be6077baeba8 Mon Sep 17 00:00:00 2001 From: Peter Sabichay Phanouvong Date: Tue, 19 Mar 2024 10:56:08 +1100 Subject: [PATCH 2/3] fix: types for build --- lib/sdk/clients/browser/authcode-with-pkce.ts | 4 ++-- lib/sdk/clients/server/authorization-code.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/sdk/clients/browser/authcode-with-pkce.ts b/lib/sdk/clients/browser/authcode-with-pkce.ts index e2c7bc7..50b1d32 100644 --- a/lib/sdk/clients/browser/authcode-with-pkce.ts +++ b/lib/sdk/clients/browser/authcode-with-pkce.ts @@ -14,6 +14,7 @@ import type { RegisterURLOptions, LoginURLOptions, BrowserPKCEClientOptions, + OAuth2CodeExchangeResponse, } from '../types.js'; const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => { @@ -271,10 +272,9 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => { /** * Method makes user of the `refreshTokens` method of the `AuthCodeWithPKCE` client * to use the refresh token to get new tokens - * @param {SessionManager} sessionManager * @returns {Promise} */ - const refreshTokens = async (sessionManager: SessionManager): Promise => { + const refreshTokens = async (): Promise => { return await client.refreshTokens(sessionManager); }; diff --git a/lib/sdk/clients/server/authorization-code.ts b/lib/sdk/clients/server/authorization-code.ts index fb0d7bb..20047d7 100644 --- a/lib/sdk/clients/server/authorization-code.ts +++ b/lib/sdk/clients/server/authorization-code.ts @@ -9,6 +9,7 @@ import type { RegisterURLOptions, LoginURLOptions, ACClientOptions, + OAuth2CodeExchangeResponse, } from '../types.js'; const createAuthorizationCodeClient = ( @@ -139,7 +140,7 @@ const createAuthorizationCodeClient = ( * @param {SessionManager} sessionManager * @returns {Promise} */ - const refreshTokens = async (sessionManager: SessionManager): Promise => { + const refreshTokens = async (sessionManager: SessionManager): Promise => { return await client.refreshTokens(sessionManager); }; From a20b84b5f3de13d4640f01fbc190ce7bbabb90fd Mon Sep 17 00:00:00 2001 From: Peter Sabichay Phanouvong Date: Tue, 19 Mar 2024 11:00:51 +1100 Subject: [PATCH 3/3] fix: type imports --- lib/sdk/clients/browser/authcode-with-pkce.ts | 5 ++++- lib/sdk/clients/server/authorization-code.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/sdk/clients/browser/authcode-with-pkce.ts b/lib/sdk/clients/browser/authcode-with-pkce.ts index 50b1d32..166050a 100644 --- a/lib/sdk/clients/browser/authcode-with-pkce.ts +++ b/lib/sdk/clients/browser/authcode-with-pkce.ts @@ -14,9 +14,12 @@ import type { RegisterURLOptions, LoginURLOptions, BrowserPKCEClientOptions, - OAuth2CodeExchangeResponse, } from '../types.js'; +import type { + OAuth2CodeExchangeResponse, +} from '../../oauth2-flows/types.js'; + const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => { const { featureFlags, tokenClaims } = utilities; const sessionManager = options.sessionManager ?? new BrowserSessionManager(); diff --git a/lib/sdk/clients/server/authorization-code.ts b/lib/sdk/clients/server/authorization-code.ts index 20047d7..616494c 100644 --- a/lib/sdk/clients/server/authorization-code.ts +++ b/lib/sdk/clients/server/authorization-code.ts @@ -9,9 +9,12 @@ import type { RegisterURLOptions, LoginURLOptions, ACClientOptions, - OAuth2CodeExchangeResponse, } from '../types.js'; +import type { + OAuth2CodeExchangeResponse, +} from '../../oauth2-flows/types.js'; + const createAuthorizationCodeClient = ( options: ACClientOptions, isPKCE: boolean