Files
accounted/extensions/general/mail/lib/callback-origin.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

30 lines
1016 B
TypeScript

/**
* Resolve the origin used to build OAuth redirect URIs.
*
* Both OAuth legs must send the same redirect_uri. Pinning it to the
* deployment's canonical app URL also prevents an old domain alias or preview
* host from generating a callback that is not registered with the provider.
* Self-hosted deployments without NEXT_PUBLIC_APP_URL fall back to the
* request origin.
*/
export function resolveCallbackOrigin(requestOrigin: string): string {
const appUrl = process.env.NEXT_PUBLIC_APP_URL
if (appUrl && appUrl.trim().length > 0) {
try {
// Normalizes trailing slashes and strips paths so the provider receives
// the same bare origin on the authorization and token-exchange legs.
const configuredUrl = new URL(appUrl)
if (
configuredUrl.protocol !== 'http:' &&
configuredUrl.protocol !== 'https:'
) {
return requestOrigin
}
return configuredUrl.origin
} catch {
return requestOrigin
}
}
return requestOrigin
}