Skip to content

Commit

Permalink
feat: authts#48 add redirectMethod to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Sep 14, 2021
1 parent f320c64 commit 14a481f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export class UserManager {
const args = {
request_type: "si:r"
};
await this._signinStart(args, this._redirectNavigator);
await this._signinStart(args, this._redirectNavigator, {
redirectMethod: this.settings.redirectMethod
});
Log.info("UserManager.signinRedirect: successful");
}
public async signinRedirectCallback(url?: string): Promise<User> {
Expand Down Expand Up @@ -123,7 +125,8 @@ export class UserManager {
const user = await this._signin(args, this._popupNavigator, {
startUrl: url,
popupWindowFeatures: this.settings.popupWindowFeatures,
popupWindowTarget: this.settings.popupWindowTarget
popupWindowTarget: this.settings.popupWindowTarget,
redirectMethod: this.settings.redirectMethod
});
if (user) {
if (user.profile && user.profile.sub) {
Expand Down Expand Up @@ -298,7 +301,8 @@ export class UserManager {
};
const navResponse = await this._signinStart(args, this._iframeNavigator, {
startUrl: url,
silentRequestTimeoutInSeconds: this.settings.silentRequestTimeoutInSeconds
silentRequestTimeoutInSeconds: this.settings.silentRequestTimeoutInSeconds,
redirectMethod: this.settings.redirectMethod
});
try {
const signinResponse = await this._client.processSigninResponse(navResponse.url);
Expand Down Expand Up @@ -339,7 +343,7 @@ export class UserManager {
const navResponse = await this._signinStart(args, navigator, navigatorParams);
return this._signinEnd(navResponse.url, args);
}
protected async _signinStart(args: SigninArgs, navigator: INavigator, navigatorParams: NavigatorParams = {}) {
protected async _signinStart(args: SigninArgs, navigator: INavigator, navigatorParams: NavigatorParams) {
const handle = await navigator.prepare(navigatorParams);
Log.debug("UserManager._signinStart: got navigator window handle");

Expand Down
5 changes: 5 additions & 0 deletions src/UserManagerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface UserManagerSettings extends OidcClientSettings {
popupWindowFeatures?: string;
/** The target parameter to window.open for the popup signin window (default: "_blank") */
popupWindowTarget?: string;
/** The methods window.location method used to redirect (default: "assign") */
redirectMethod?: "replace" | "assign";

/** The URL for the page containing the code handling the silent renew */
silent_redirect_uri?: string;
Expand Down Expand Up @@ -51,6 +53,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {
public readonly popup_post_logout_redirect_uri: string | undefined;
public readonly popupWindowFeatures: string | undefined;
public readonly popupWindowTarget: string | undefined;
public readonly redirectMethod: "replace" | "assign" | undefined;

public readonly silent_redirect_uri: string | undefined;
public readonly silentRequestTimeoutInSeconds: number | undefined;
Expand All @@ -75,6 +78,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {
popup_post_logout_redirect_uri,
popupWindowFeatures,
popupWindowTarget,
redirectMethod,
silent_redirect_uri,
silentRequestTimeoutInSeconds,
automaticSilentRenew = false,
Expand All @@ -96,6 +100,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {
this.popup_post_logout_redirect_uri = popup_post_logout_redirect_uri;
this.popupWindowFeatures = popupWindowFeatures;
this.popupWindowTarget = popupWindowTarget;
this.redirectMethod = redirectMethod;

this.silent_redirect_uri = silent_redirect_uri;
this.silentRequestTimeoutInSeconds = silentRequestTimeoutInSeconds;
Expand Down
17 changes: 17 additions & 0 deletions test/unit/UserManagerSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ describe("UserManagerSettings", () => {

});

describe("redirectMethod", () => {

it("should return value from initial settings", () => {
// act
const subject = new UserManagerSettingsStore({
authority: "authority",
client_id: "client",
redirect_uri: "redirect",
redirectMethod: "replace"
});

// assert
expect(subject.redirectMethod).toEqual("replace");
});

});

describe("silent_redirect_uri", () => {

it("should return value from initial settings", () => {
Expand Down

0 comments on commit 14a481f

Please sign in to comment.