Skip to content

Commit b030b7d

Browse files
ysemennikovatinux
andauthored
fix(zitadel): don't prefix domain with https:// if another protocol is used (#475)
Co-authored-by: Sébastien Chopin <[email protected]>
1 parent 7609542 commit b030b7d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/runtime/server/lib/oauth/zitadel.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { H3Event } from 'h3'
22
import { eventHandler, getQuery, sendRedirect } from 'h3'
3-
import { withQuery } from 'ufo'
3+
import { hasProtocol, withQuery } from 'ufo'
44
import { defu } from 'defu'
55
import type { RequestAccessTokenOptions } from '../utils'
66
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken, handleState, handlePkceVerifier, handleInvalidState } from '../utils'
@@ -65,8 +65,9 @@ export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: O
6565
return handleMissingConfiguration(event, 'zitadel', ['clientId', 'domain'], onError)
6666
}
6767

68-
const authorizationURL = `https://${config.domain}/oauth/v2/authorize`
69-
const tokenURL = `https://${config.domain}/oauth/v2/token`
68+
const domain = hasProtocol(config.domain as string) ? config.domain : `https://${config.domain}`
69+
const authorizationURL = `${domain}/oauth/v2/authorize`
70+
const tokenURL = `${domain}/oauth/v2/token`
7071
const redirectURL = config.redirectURL || getOAuthRedirectURL(event)
7172

7273
// Create pkce verifier
@@ -123,7 +124,7 @@ export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: O
123124
const accessToken = tokens.access_token
124125
// Fetch user info
125126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
126-
const user: any = await $fetch(`https://${config.domain}/oidc/v1/userinfo`, {
127+
const user: any = await $fetch(`${domain}/oidc/v1/userinfo`, {
127128
headers: {
128129
Authorization: `Bearer ${accessToken}`,
129130
Accept: 'application/json',

0 commit comments

Comments
 (0)