Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/runtime/server/lib/oauth/zitadel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { H3Event } from 'h3'
import { eventHandler, getQuery, sendRedirect } from 'h3'
import { withQuery } from 'ufo'
import { hasProtocol, withQuery } from 'ufo'
import { defu } from 'defu'
import type { RequestAccessTokenOptions } from '../utils'
import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken, handleState, handlePkceVerifier, handleInvalidState } from '../utils'
Expand Down Expand Up @@ -65,8 +65,9 @@ export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: O
return handleMissingConfiguration(event, 'zitadel', ['clientId', 'domain'], onError)
}

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

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