Skip to content
Draft
Changes from 1 commit
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
33 changes: 32 additions & 1 deletion src/AuthorizationCodeFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,18 @@ export class AuthorizationCodeFlow extends HTMLElement {
const onMessage = (message: MessageEvent) => {
signal.removeEventListener("abort", onAbort)
this.#switchModal.close()
this.#authorizationWindow?.close()

// When the server answered a silent (`prompt=none`) attempt with a "user
Comment on lines 189 to +201

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1ce81c1: the listener now ignores any message whose source is not the authorization popup, and removes itself on the matching message instead of using { once: true }.

// interaction needed" error, the caller is about to retry interactively.
// Keep the popup open: the retry's `open()` then NAVIGATES this named
// window, which browsers allow without user activation. Closing it here
// would make the retry create a new window — popup blockers stop that
// (the original click's activation is already consumed), stranding the
// user in the "open new window" dialog.
if (!needsInteraction(message.data)) {
this.#authorizationWindow?.close()
}

respondWithCode(message.data)
}

Expand Down Expand Up @@ -247,3 +258,23 @@ export class AuthorizationCodeFlow extends HTMLElement {
this.#cancelCodeRequest?.call(undefined, new CodeRequestCancelledError(this.#authorizationUri!))
}
}

/**
* Whether the authorization response is one of the OIDC "the user must interact"
* errors — exactly the errors token providers retry interactively right away.
* Anything else (a code, or a terminal error such as `access_denied`) ends the flow.
*/
function needsInteraction(authorizationResponse: unknown): boolean {
if (typeof authorizationResponse !== "string") {
return false
}

let error
try {
error = new URL(authorizationResponse).searchParams.get("error")
} catch {
return false
}

return error === "login_required" || error === "interaction_required" || error === "consent_required"
}
Loading