From 0223d6a985cbf9da13c7e1579fbdf8cd2c1bc916 Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Tue, 9 Apr 2024 14:05:00 +0530 Subject: [PATCH] Add config to disable token refresh logic --- lib/src/client.ts | 1 + lib/src/helpers/spa-helper.ts | 7 +++++++ lib/src/models/client-config.ts | 1 + 3 files changed, 9 insertions(+) diff --git a/lib/src/client.ts b/lib/src/client.ts index 8a60a584..a074c45c 100755 --- a/lib/src/client.ts +++ b/lib/src/client.ts @@ -54,6 +54,7 @@ const DefaultConfig: Partial> = { checkSessionInterval: 3, clientHost: origin, enableOIDCSessionManagement: false, + periodicTokenRefresh: false, sessionRefreshInterval: 300, storage: Storage.SessionStorage }; diff --git a/lib/src/helpers/spa-helper.ts b/lib/src/helpers/spa-helper.ts index 6199e334..72b5de54 100644 --- a/lib/src/helpers/spa-helper.ts +++ b/lib/src/helpers/spa-helper.ts @@ -33,6 +33,13 @@ export class SPAHelper MainThreadClientConfig | WebWorkerClientConfig > ): Promise { + const shouldRefreshAutomatically: boolean = (await this._dataLayer.getConfigData())?.periodicTokenRefresh ?? + false; + + if (!shouldRefreshAutomatically) { + return; + } + const sessionData = await this._dataLayer.getSessionData(); if (sessionData.refresh_token) { // Refresh 10 seconds before the expiry time diff --git a/lib/src/models/client-config.ts b/lib/src/models/client-config.ts index 1278307e..2047e373 100644 --- a/lib/src/models/client-config.ts +++ b/lib/src/models/client-config.ts @@ -31,6 +31,7 @@ export interface SPAConfig { sessionRefreshInterval?: number; resourceServerURLs?: string[]; authParams?: Record + periodicTokenRefresh?: boolean; } /**