Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make signinPopup work when calling window is iframe #1744

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/oidc-client-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class OidcClient {
processSignoutResponse(url: string): Promise<SignoutResponse>;
// (undocumented)
readSigninResponseState(url: string, removeState?: boolean): Promise<{
state: SigninState;
state: SigninState | undefined;
response: SigninResponse;
}>;
// (undocumented)
Expand Down
13 changes: 7 additions & 6 deletions src/OidcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class OidcClient {
return signinRequest;
}

public async readSigninResponseState(url: string, removeState = false): Promise<{ state: SigninState; response: SigninResponse }> {
public async readSigninResponseState(url: string, removeState = false): Promise<{ state: SigninState|undefined; response: SigninResponse }> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add spaces in-between: SigninState | undefined

const logger = this._logger.create("readSigninResponseState");

const response = new SigninResponse(UrlUtils.readParams(url, this.settings.response_mode));
Expand All @@ -163,12 +163,8 @@ export class OidcClient {
}

const storedStateString = await this.settings.stateStore[removeState ? "remove" : "get"](response.state);
if (!storedStateString) {
logger.throw(new Error("No matching state found in storage"));
throw null; // https://github.com/microsoft/TypeScript/issues/46972
}

const state = await SigninState.fromStorageString(storedStateString);
const state = storedStateString ? await SigninState.fromStorageString(storedStateString) : undefined;
return { state, response };
}

Expand All @@ -183,6 +179,11 @@ export class OidcClient {
extraHeaders = { ...extraHeaders, "DPoP": dpopProof };
}

if (!state) {
logger.throw(new Error("No state was found in storage or response"));
throw null; //
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please re-add comment from above // https://github.com/microsoft/TypeScript/issues/46972

}

/**
* The DPoP spec describes a method for Authorization Servers to supply a nonce value
* in order to limit the lifetime of a given DPoP proof.
Expand Down
7 changes: 7 additions & 0 deletions src/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ export class UserManager {
*/
public async signinCallback(url = window.location.href): Promise<User | undefined> {
const { state } = await this._client.readSigninResponseState(url);

// if no state from storage, assume signin popup
if (state === undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state === undefined -> !state

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we sure it was a "signin popup request" here? What about "No matching state found in storage" in the non "signin popup" request case?

await this.signinPopupCallback(url);
return undefined;
}

switch (state.request_type) {
case "si:r":
return await this.signinRedirectCallback(url);
Expand Down
Loading