Skip to content

Commit

Permalink
handle undefined oidc host
Browse files Browse the repository at this point in the history
  • Loading branch information
glasstiger committed Nov 20, 2024
1 parent c05a56d commit 591e7f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/web-console/src/modules/OAuth2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ type TokenPayload = Partial<{
refresh_token: string
}>

const getBaseURL = (settings: Settings) => {
// if there is no host in settings, no need to construct base URL at all
if (!settings["acl.oidc.host"]) {
return "";
}

// if there is host in settings, we are in legacy mode, and we should construct the base URL
return `${settings["acl.oidc.tls.enabled"] ? "https" : "http"}://${
settings["acl.oidc.host"]
}:${settings["acl.oidc.port"]}`
}

export const getAuthorisationURL = ({
settings,
code_challenge = null,
Expand Down Expand Up @@ -37,6 +49,7 @@ export const getAuthorisationURL = ({
}

return (
getBaseURL(settings) +
settings["acl.oidc.authorization.endpoint"] +
"?" +
urlParams
Expand All @@ -52,7 +65,7 @@ export const getAuthToken = async (
payload: TokenPayload,
) => {
return fetch(
`${settings["acl.oidc.token.endpoint"]}`,
`${getBaseURL(settings)}${settings["acl.oidc.token.endpoint"]}`,
{
method: "POST",
headers: {
Expand Down
3 changes: 3 additions & 0 deletions packages/web-console/src/providers/SettingsProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type Settings = Partial<{
"acl.oidc.client.id": string
"acl.oidc.redirect.uri": string
"acl.oidc.scope": string
"acl.oidc.host": string
"acl.oidc.port": number
"acl.oidc.tls.enabled": boolean
"acl.oidc.authorization.endpoint": string
"acl.oidc.token.endpoint": string
"acl.oidc.pkce.required": boolean
Expand Down

0 comments on commit 591e7f7

Please sign in to comment.