Skip to content

Commit d0f7c72

Browse files
muscionignsarrazin
andauthored
fix: parse ISS if returned in OIDC flow (#1162)
fix: parse iss and pass when available Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
1 parent b47cd67 commit d0f7c72

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/lib/server/auth.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ export async function getOIDCAuthorizationUrl(
110110
});
111111
}
112112

113-
export async function getOIDCUserData(settings: OIDCSettings, code: string): Promise<OIDCUserInfo> {
113+
export async function getOIDCUserData(
114+
settings: OIDCSettings,
115+
code: string,
116+
iss?: string
117+
): Promise<OIDCUserInfo> {
114118
const client = await getOIDCClient(settings);
115-
const token = await client.callback(settings.redirectURI, { code });
119+
const token = await client.callback(settings.redirectURI, { code, iss });
116120
const userData = await client.userinfo(token);
117121

118122
return { token, userData };

src/routes/login/callback/+page.server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ export async function load({ url, locals, cookies, request, getClientAddress })
2424
throw error(400, errorName + (errorDescription ? ": " + errorDescription : ""));
2525
}
2626

27-
const { code, state } = z
27+
const { code, state, iss } = z
2828
.object({
2929
code: z.string(),
3030
state: z.string(),
31+
iss: z.string().optional(),
3132
})
3233
.parse(Object.fromEntries(url.searchParams.entries()));
3334

@@ -39,7 +40,11 @@ export async function load({ url, locals, cookies, request, getClientAddress })
3940
throw error(403, "Invalid or expired CSRF token");
4041
}
4142

42-
const { userData } = await getOIDCUserData({ redirectURI: validatedToken.redirectUrl }, code);
43+
const { userData } = await getOIDCUserData(
44+
{ redirectURI: validatedToken.redirectUrl },
45+
code,
46+
iss
47+
);
4348

4449
// Filter by allowed user emails
4550
if (allowedUserEmails.length > 0) {

0 commit comments

Comments
 (0)