Skip to content

Commit

Permalink
Be more resilient with the publicUrl parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Oct 24, 2023
1 parent 294c17a commit 3569961
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,21 @@ export async function createOidc(params: {
clientId,
transformUrlBeforeRedirect = url => url,
getExtraQueryParams,
publicUrl = ""
publicUrl: publicUrl_params
} = params;

const publicUrl = (() => {
if (publicUrl_params === undefined) {
return window.location.origin;
}

if (publicUrl_params.startsWith("http")) {
return publicUrl_params.replace(/\/$/, "");
}

return `${window.location.origin}${publicUrl_params}`;
})();

const configHash = fnv1aHashToHex(`${issuerUri} ${clientId}`);
const configHashKey = "configHash";

Expand All @@ -82,7 +94,7 @@ export async function createOidc(params: {
"response_type": "code",
"scope": "openid profile",
"automaticSilentRenew": false,
"silent_redirect_uri": `${window.location.origin}${publicUrl}/silent-sso.html?${configHashKey}=${configHash}`
"silent_redirect_uri": `${publicUrl}/silent-sso.html?${configHashKey}=${configHash}`
});

const login: Oidc.NotLoggedIn["login"] = async ({
Expand Down Expand Up @@ -344,7 +356,7 @@ export async function createOidc(params: {
case "current page":
return window.location.href;
case "home":
return `${window.location.origin}${publicUrl}`;
return publicUrl;
case "specific url":
return params.url;
}
Expand Down

0 comments on commit 3569961

Please sign in to comment.