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

feat: explicit config of id token alg (#1567) #1568

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions src/lib/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const OIDConfig = z
),
TOLERANCE: stringWithDefault(env.OPENID_TOLERANCE),
RESOURCE: stringWithDefault(env.OPENID_RESOURCE),
ID_TOKEN_SIGNED_RESPONSE_ALG: z.string().optional(),
})
.parse(JSON5.parse(env.OPENID_CONFIG || "{}"));

Expand Down Expand Up @@ -103,13 +104,21 @@ export async function generateCsrfToken(sessionId: string, redirectUrl: string):
async function getOIDCClient(settings: OIDCSettings): Promise<BaseClient> {
const issuer = await Issuer.discover(OIDConfig.PROVIDER_URL);

return new issuer.Client({
const client_config: ConstructorParameters<typeof issuer.Client>[0] = {
client_id: OIDConfig.CLIENT_ID,
client_secret: OIDConfig.CLIENT_SECRET,
redirect_uris: [settings.redirectURI],
response_types: ["code"],
[custom.clock_tolerance]: OIDConfig.TOLERANCE || undefined,
});
id_token_signed_response_alg: OIDConfig.ID_TOKEN_SIGNED_RESPONSE_ALG || undefined,
};

const alg_supported = issuer.metadata["id_token_signing_alg_values_supported"];

if (Array.isArray(alg_supported) && !alg_supported.includes("RS256")) {
client_config.id_token_signed_response_alg ??= alg_supported[0];
}
return new issuer.Client(client_config);
}

export async function getOIDCAuthorizationUrl(
Expand Down