From 6e899480d55bd5b0a81731b77d8783262433ebeb Mon Sep 17 00:00:00 2001 From: Jakob Ankarhem Date: Tue, 11 Oct 2022 18:25:34 +0200 Subject: [PATCH] fix(oidc): allow paths in wellknown lookup --- server/utils/oidc.ts | 16 +++++++--------- src/components/Login/OIDCLoginButton.tsx | 3 ++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/server/utils/oidc.ts b/server/utils/oidc.ts index 346c9a197..a24cef3a0 100644 --- a/server/utils/oidc.ts +++ b/server/utils/oidc.ts @@ -4,15 +4,13 @@ import * as yup from 'yup'; /** Fetch the oidc configuration blob */ export async function getOIDCWellknownConfiguration(domain: string) { - const wellKnownInfo: WellKnownConfiguration = await fetch( - new URL( - '/.well-known/openid-configuration', - `https://${domain}` - ).toString(), - { - headers: new Headers([['Content-Type', 'application/json']]), - } - ).then((r) => r.json()); + // remove trailing slash from url if it exists and add /.well-known/openid-configuration path + const wellKnownUrl = new URL( + `https://${domain}`.replace(/\/$/, '') + '/.well-known/openid-configuration' + ).toString(); + const wellKnownInfo: WellKnownConfiguration = await fetch(wellKnownUrl, { + headers: new Headers([['Content-Type', 'application/json']]), + }).then((r) => r.json()); return wellKnownInfo; } diff --git a/src/components/Login/OIDCLoginButton.tsx b/src/components/Login/OIDCLoginButton.tsx index 8cddd67bd..81dbd1eeb 100644 --- a/src/components/Login/OIDCLoginButton.tsx +++ b/src/components/Login/OIDCLoginButton.tsx @@ -26,8 +26,9 @@ function OIDCLoginButton({ revalidate, oidcName }: Props) { } catch (e) { setLoading(false); return; + } finally { + setLoading(false); } - setLoading(false); }; return (