Skip to content

Commit

Permalink
fix: authts#13 convert checkSessionInterval (milliseconds) to checkSe…
Browse files Browse the repository at this point in the history
…ssionIntervalInSeconds in settings
  • Loading branch information
pamapa committed Sep 8, 2021
1 parent 0f7005c commit 7d41514
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
12 changes: 5 additions & 7 deletions src/CheckSessionIFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@

import { Log } from "./utils";

const DefaultInterval = 2000;

export class CheckSessionIFrame {
private _callback: () => Promise<void> | void;
private _client_id: string;
private _interval: number;
private _intervalInSeconds: number;
private _stopOnError: boolean;
private _frame_origin: string;
private _frame: HTMLIFrameElement;
private _boundMessageEvent: ((e: MessageEvent<string>) => void) | null;
private _timer: number | null;
private _session_state: string | null;

public constructor(callback: () => Promise<void> | void, client_id: string, url: string, interval?: number, stopOnError?: boolean) {
public constructor(callback: () => Promise<void> | 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);
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/SessionMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/UserManagerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/unit/UserManagerSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -294,7 +294,7 @@ describe("UserManagerSettings", () => {
});

// assert
expect(subject.checkSessionInterval).toEqual(2000);
expect(subject.checkSessionIntervalInSeconds).toEqual(2);
});
});

Expand Down

0 comments on commit 7d41514

Please sign in to comment.