Include openid scope in OIDC authentication requests

This commit is contained in:
Maurus Decimus
2026-04-25 08:14:47 +02:00
parent 68f0ca3629
commit 2344c96651
3 changed files with 18 additions and 8 deletions
+11 -3
View File
@@ -17,6 +17,7 @@ interface DiscoveryResponse {
authorization_endpoint: string;
token_endpoint: string;
end_session_endpoint?: string;
scopes_supported?: string[];
}
export async function discover(username: string): Promise<DiscoveryResponse> {
@@ -124,7 +125,8 @@ function getRedirectUri(): string {
}
export async function startAuthFlow(username: string, returnUrl?: string | null): Promise<void> {
const { authorization_endpoint, token_endpoint, end_session_endpoint } = await discover(username);
const { authorization_endpoint, token_endpoint, end_session_endpoint, scopes_supported } =
await discover(username);
const codeVerifier = generateCodeVerifier();
const { challenge: codeChallenge, method: codeChallengeMethod } = await generateCodeChallenge(codeVerifier);
@@ -161,8 +163,14 @@ export async function startAuthFlow(username: string, returnUrl?: string | null)
prompt: 'login',
});
if (SCOPES && SCOPES.length > 0) {
params.set('scope', SCOPES);
const scope =
SCOPES && SCOPES.length > 0
? SCOPES
: scopes_supported?.includes('openid')
? 'openid'
: '';
if (scope) {
params.set('scope', scope);
}
window.location.href = `${authorization_endpoint}?${params.toString()}`;