diff --git a/src/CheckSessionIFrame.ts b/src/CheckSessionIFrame.ts index 4fdc1a4cc..5bef28c07 100644 --- a/src/CheckSessionIFrame.ts +++ b/src/CheckSessionIFrame.ts @@ -3,12 +3,10 @@ import { Log } from "./utils"; -const DefaultInterval = 2000; - export class CheckSessionIFrame { private _callback: () => Promise | void; private _client_id: string; - private _interval: number; + private _intervalInSeconds: number; private _stopOnError: boolean; private _frame_origin: string; private _frame: HTMLIFrameElement; @@ -16,11 +14,11 @@ export class CheckSessionIFrame { private _timer: number | null; private _session_state: string | null; - public constructor(callback: () => Promise | void, client_id: string, url: string, interval?: number, stopOnError?: boolean) { + public constructor(callback: () => Promise | void, client_id: string, url: string, intervalInSeconds: number, stopOnError: boolean) { this._callback = callback; this._client_id = client_id; - this._interval = interval || DefaultInterval; - this._stopOnError = stopOnError || true; + this._intervalInSeconds = intervalInSeconds; + this._stopOnError = stopOnError; const idx = url.indexOf("/", url.indexOf("//") + 2); this._frame_origin = url.substr(0, idx); @@ -96,7 +94,7 @@ export class CheckSessionIFrame { send(); // and setup timer - this._timer = window.setInterval(send, this._interval); + this._timer = window.setInterval(send, this._intervalInSeconds * 1000); } public stop() { diff --git a/src/SessionMonitor.ts b/src/SessionMonitor.ts index 43a3ff241..691b8c7a1 100644 --- a/src/SessionMonitor.ts +++ b/src/SessionMonitor.ts @@ -82,10 +82,10 @@ export class SessionMonitor { Log.debug("SessionMonitor._start: Initializing check session iframe"); const client_id = this._userManager.settings.client_id; - const interval = this._userManager.settings.checkSessionInterval; + const intervalInSeconds = this._userManager.settings.checkSessionIntervalInSeconds; const stopOnError = this._userManager.settings.stopCheckSessionOnError; - this._checkSessionIFrame = new CheckSessionIFrame(this._callback.bind(this), client_id, url, interval, stopOnError); + this._checkSessionIFrame = new CheckSessionIFrame(this._callback.bind(this), client_id, url, intervalInSeconds, stopOnError); await this._checkSessionIFrame.load(); this._checkSessionIFrame && this._checkSessionIFrame.start(session_state); diff --git a/src/UserManagerSettings.ts b/src/UserManagerSettings.ts index c50fb7819..abbc5e416 100644 --- a/src/UserManagerSettings.ts +++ b/src/UserManagerSettings.ts @@ -6,7 +6,7 @@ import { WebStorageStateStore } from "./WebStorageStateStore"; import { SigninRequest } from "./SigninRequest"; const DefaultAccessTokenExpiringNotificationTimeInSeconds = 60; -const DefaultCheckSessionInterval = 2000; +const DefaultCheckSessionIntervalInSeconds = 2; export interface UserManagerSettings extends OidcClientSettings { /** The URL for the page containing the call to signinPopupCallback to handle the callback from the OIDC/OAuth2 */ @@ -32,8 +32,8 @@ export interface UserManagerSettings extends OidcClientSettings { /** Will raise events for when user has performed a signout at the OP (default: true) */ monitorSession?: boolean; monitorAnonymousSession?: boolean; - /** Interval, in ms, to check the user's session (default: 2000) */ - checkSessionInterval?: number; + /** Interval in seconds to check the user's session (default: 2) */ + checkSessionIntervalInSeconds?: number; query_status_response_type?: string; stopCheckSessionOnError?: boolean; @@ -60,9 +60,9 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore { public readonly monitorSession: boolean; public readonly monitorAnonymousSession: boolean; - public readonly checkSessionInterval: number; + public readonly checkSessionIntervalInSeconds: number; public readonly query_status_response_type: string | undefined; - public readonly stopCheckSessionOnError: boolean | undefined; + public readonly stopCheckSessionOnError: boolean; public readonly revokeAccessTokenOnSignout: boolean; public readonly accessTokenExpiringNotificationTimeInSeconds: number; @@ -82,7 +82,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore { includeIdTokenInSilentRenew = true, monitorSession = true, monitorAnonymousSession = false, - checkSessionInterval = DefaultCheckSessionInterval, + checkSessionIntervalInSeconds = DefaultCheckSessionIntervalInSeconds, stopCheckSessionOnError = true, query_status_response_type, revokeAccessTokenOnSignout = false, @@ -105,7 +105,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore { this.monitorSession = monitorSession; this.monitorAnonymousSession = monitorAnonymousSession; - this.checkSessionInterval = checkSessionInterval; + this.checkSessionIntervalInSeconds = checkSessionIntervalInSeconds; this.stopCheckSessionOnError = stopCheckSessionOnError; if (query_status_response_type) { this.query_status_response_type = query_status_response_type; diff --git a/test/unit/UserManagerSettings.test.ts b/test/unit/UserManagerSettings.test.ts index bb64768cf..8477d4447 100644 --- a/test/unit/UserManagerSettings.test.ts +++ b/test/unit/UserManagerSettings.test.ts @@ -279,11 +279,11 @@ describe("UserManagerSettings", () => { authority: "authority", client_id: "client", redirect_uri: "redirect", - checkSessionInterval : 6000 + checkSessionIntervalInSeconds: 6 }); // assert - expect(subject.checkSessionInterval).toEqual(6000); + expect(subject.checkSessionIntervalInSeconds).toEqual(6); }); it("should use default value", () => { // act @@ -294,7 +294,7 @@ describe("UserManagerSettings", () => { }); // assert - expect(subject.checkSessionInterval).toEqual(2000); + expect(subject.checkSessionIntervalInSeconds).toEqual(2); }); });