|
1 | 1 | import type { H3Event } from 'h3' |
2 | 2 | import { eventHandler, getQuery, sendRedirect } from 'h3' |
3 | | -import { withQuery } from 'ufo' |
| 3 | +import { hasProtocol, withQuery } from 'ufo' |
4 | 4 | import { defu } from 'defu' |
5 | 5 | import type { RequestAccessTokenOptions } from '../utils' |
6 | 6 | import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken, handleState, handlePkceVerifier, handleInvalidState } from '../utils' |
@@ -65,8 +65,9 @@ export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: O |
65 | 65 | return handleMissingConfiguration(event, 'zitadel', ['clientId', 'domain'], onError) |
66 | 66 | } |
67 | 67 |
|
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` |
70 | 71 | const redirectURL = config.redirectURL || getOAuthRedirectURL(event) |
71 | 72 |
|
72 | 73 | // Create pkce verifier |
@@ -123,7 +124,7 @@ export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: O |
123 | 124 | const accessToken = tokens.access_token |
124 | 125 | // Fetch user info |
125 | 126 | // 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`, { |
127 | 128 | headers: { |
128 | 129 | Authorization: `Bearer ${accessToken}`, |
129 | 130 | Accept: 'application/json', |
|
0 commit comments