Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
fix: #13 convert silentRequestTimeout (milliseconds) to silentRequest…
Browse files Browse the repository at this point in the history
…TimeoutInSeconds in settings
  • Loading branch information
pamapa committed Sep 8, 2021
1 parent 3715389 commit 0f7005c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class UserManager extends OidcClient {

const user = await this._signin(args, this._iframeNavigator, {
startUrl: url,
silentRequestTimeout: this.settings.silentRequestTimeout
silentRequestTimeoutInSeconds: this.settings.silentRequestTimeoutInSeconds
});
if (user) {
if (user.profile && user.profile.sub) {
Expand Down Expand Up @@ -294,7 +294,7 @@ export class UserManager extends OidcClient {
};
const navResponse = await this._signinStart(args, this._iframeNavigator, {
startUrl: url,
silentRequestTimeout: this.settings.silentRequestTimeout
silentRequestTimeoutInSeconds: this.settings.silentRequestTimeoutInSeconds
});
try {
const signinResponse = await this.processSigninResponse(navResponse.url);
Expand Down
10 changes: 5 additions & 5 deletions src/UserManagerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export interface UserManagerSettings extends OidcClientSettings {

/** The URL for the page containing the code handling the silent renew */
silent_redirect_uri?: string;
/** Number of milliseconds to wait for the silent renew to return before assuming it has failed or timed out (default: 10000) */
silentRequestTimeout?: number;
/** Number of seconds to wait for the silent renew to return before assuming it has failed or timed out (default: 10) */
silentRequestTimeoutInSeconds?: number;
/** Flag to indicate if there should be an automatic attempt to renew the access token prior to its expiration (default: false) */
automaticSilentRenew?: boolean;
validateSubOnSilentRenew?: boolean;
Expand Down Expand Up @@ -53,7 +53,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {
public readonly popupWindowTarget: string | undefined;

public readonly silent_redirect_uri: string | undefined;
public readonly silentRequestTimeout: number | undefined;
public readonly silentRequestTimeoutInSeconds: number | undefined;
public readonly automaticSilentRenew: boolean;
public readonly validateSubOnSilentRenew: boolean;
public readonly includeIdTokenInSilentRenew: boolean;
Expand All @@ -76,7 +76,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {
popupWindowFeatures,
popupWindowTarget,
silent_redirect_uri,
silentRequestTimeout,
silentRequestTimeoutInSeconds,
automaticSilentRenew = false,
validateSubOnSilentRenew = false,
includeIdTokenInSilentRenew = true,
Expand All @@ -98,7 +98,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {
this.popupWindowTarget = popupWindowTarget;

this.silent_redirect_uri = silent_redirect_uri;
this.silentRequestTimeout = silentRequestTimeout;
this.silentRequestTimeoutInSeconds = silentRequestTimeoutInSeconds;
this.automaticSilentRenew = automaticSilentRenew;
this.validateSubOnSilentRenew = validateSubOnSilentRenew;
this.includeIdTokenInSilentRenew = includeIdTokenInSilentRenew;
Expand Down
8 changes: 4 additions & 4 deletions src/navigators/IFrameWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Log } from "../utils";
import { IWindow, NavigatorParams } from "./IWindow";

const DefaultTimeout = 10000;
const DefaultTimeoutInSeconds = 10;

export class IFrameWindow implements IWindow {
private _promise: Promise<unknown>;
Expand Down Expand Up @@ -44,9 +44,9 @@ export class IFrameWindow implements IWindow {
this._error("No _frame, already closed");
}
else {
const timeout = params.silentRequestTimeout || DefaultTimeout;
Log.debug("IFrameWindow.navigate: Using timeout of:", timeout);
this._timer = window.setTimeout(this._timeout.bind(this), timeout);
const timeoutInSeconds = params.silentRequestTimeoutInSeconds || DefaultTimeoutInSeconds;
Log.debug("IFrameWindow.navigate: Using timeout of:", timeoutInSeconds);
this._timer = window.setTimeout(this._timeout.bind(this), timeoutInSeconds * 1000);
this._frame.src = params.url;
}

Expand Down
2 changes: 1 addition & 1 deletion src/navigators/IWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface NavigatorParams {
startUrl?: string;
popupWindowFeatures?: string;
popupWindowTarget?: string;
silentRequestTimeout?: number;
silentRequestTimeoutInSeconds?: number;
redirectMethod?: "replace" | "assign";
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/UserManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("UserManager", () => {

settings = {
...settings,
silentRequestTimeout: 123,
silentRequestTimeoutInSeconds: 123,
silent_redirect_uri: "http://client/silent_callback"
};
subject = new UserManager(settings);
Expand All @@ -92,7 +92,7 @@ describe("UserManager", () => {
await subject.signinSilent();

// assert
expect(navArgs.silentRequestTimeout).toEqual(123);
expect(navArgs.silentRequestTimeoutInSeconds).toEqual(123);
});

it("should work when having no User present", async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/UserManagerSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ describe("UserManagerSettings", () => {
authority: "authority",
client_id: "client",
redirect_uri: "redirect",
silentRequestTimeout: 123
silentRequestTimeoutInSeconds: 123
});

// assert
expect(subject.silentRequestTimeout).toEqual(123);
expect(subject.silentRequestTimeoutInSeconds).toEqual(123);
});

});
Expand Down

0 comments on commit 0f7005c

Please sign in to comment.