mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
fix(auth): ask the provider for a fresh sign-in when claiming a profile
This commit is contained in:
1 parent
23f008c8bb
commit
3c44f3d167
4 files changed
+72
-1
No files matched your search
@@ -253,6 +253,23 @@ describe("buildAuthorizationUrl", () => {
|
||||
expect(url.searchParams.get("code_challenge")).toBe("challenge-1");
|
||||
expect(url.searchParams.get("code_challenge_method")).toBe("S256");
|
||||
expect(url.searchParams.get("scope")).toBe(config.scopes);
|
||||
expect(url.searchParams.has("prompt")).toBe(false);
|
||||
});
|
||||
|
||||
it("asks for a fresh sign-in only when told to", () => {
|
||||
configureEnv();
|
||||
const url = new URL(
|
||||
buildAuthorizationUrl({
|
||||
metadata: METADATA_DOC,
|
||||
config: getOidcConfig()!,
|
||||
state: "state-1",
|
||||
nonce: "nonce-1",
|
||||
codeChallenge: "challenge-1",
|
||||
redirectUri: "https://healthlog.example.com/api/auth/oidc/callback",
|
||||
forceLogin: true,
|
||||
}),
|
||||
);
|
||||
expect(url.searchParams.get("prompt")).toBe("login");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -237,6 +237,13 @@ export function buildAuthorizationUrl(params: {
|
||||
nonce: string;
|
||||
codeChallenge: string;
|
||||
redirectUri: string;
|
||||
/**
|
||||
* Ask the provider to authenticate afresh (`prompt=login`, OpenID Connect
|
||||
* Core 3.1.2.1) instead of reusing the browser's provider session. A claim
|
||||
* hands a profile to whoever signs in, so it must be the person at the
|
||||
* keyboard now, not a session someone else left open in this browser.
|
||||
*/
|
||||
forceLogin?: boolean;
|
||||
}): string {
|
||||
const url = new URL(params.metadata.authorization_endpoint);
|
||||
url.search = new URLSearchParams({
|
||||
@@ -248,6 +255,7 @@ export function buildAuthorizationUrl(params: {
|
||||
nonce: params.nonce,
|
||||
code_challenge: params.codeChallenge,
|
||||
code_challenge_method: "S256",
|
||||
...(params.forceLogin ? { prompt: "login" } : {}),
|
||||
}).toString();
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user