diff --git a/packages/core-app-api/src/apis/implementations/AuthErrorApi/SignInAuthErrorApi.ts b/packages/core-app-api/src/apis/implementations/AuthErrorApi/SignInAuthErrorApi.ts index 0197f253ab..2f2ba9cb09 100644 --- a/packages/core-app-api/src/apis/implementations/AuthErrorApi/SignInAuthErrorApi.ts +++ b/packages/core-app-api/src/apis/implementations/AuthErrorApi/SignInAuthErrorApi.ts @@ -31,6 +31,9 @@ export class SignInAuthErrorApi implements AuthErrorApi { async getSignInAuthError(): Promise { const baseUrl = await this.discoveryApi.getBaseUrl('auth'); + + // use native fetch instead of depending on fetchApi because + // we are not signed in and are calling an unauthenticated endpoint const response = await fetch(`${baseUrl}/.backstage/error`, { credentials: 'include', }); diff --git a/plugins/auth-node/src/oauth/createAuthErrorCookie.ts b/plugins/auth-node/src/oauth/createAuthErrorCookie.ts index 05b1c99cee..61914e7c05 100644 --- a/plugins/auth-node/src/oauth/createAuthErrorCookie.ts +++ b/plugins/auth-node/src/oauth/createAuthErrorCookie.ts @@ -21,8 +21,8 @@ const ONE_MINUTE_MS = 60 * 1000; const AUTH_ERROR_COOKIE = 'auth-error'; -function configureAuthErrorCookie(redirectUrl: string, appOrigin: string) { - const { hostname: domain, pathname: path, protocol } = new URL(redirectUrl); +function configureAuthErrorCookie(apiUrl: string, appOrigin: string) { + const { hostname: domain, pathname: path, protocol } = new URL(apiUrl); const secure = protocol === 'https:'; // For situations where the auth-backend is running on a @@ -42,15 +42,15 @@ export function createAuthErrorCookie( origin: string, options: { error: Error; - redirectUrl: string; + apiUrl: string; }, ) { - const { error, redirectUrl } = options; + const { error, apiUrl } = options; const jsonData = serializeError(error); res.cookie(AUTH_ERROR_COOKIE, jsonData, { maxAge: ONE_MINUTE_MS, httpOnly: true, - ...configureAuthErrorCookie(redirectUrl, origin), + ...configureAuthErrorCookie(apiUrl, origin), }); } diff --git a/plugins/auth-node/src/oauth/createOAuthRouteHandlers.ts b/plugins/auth-node/src/oauth/createOAuthRouteHandlers.ts index 649c094dba..847dc4844f 100644 --- a/plugins/auth-node/src/oauth/createOAuthRouteHandlers.ts +++ b/plugins/auth-node/src/oauth/createOAuthRouteHandlers.ts @@ -254,7 +254,7 @@ export function createOAuthRouteHandlers( if (state?.flow === 'redirect' && state?.redirectUrl) { createAuthErrorCookie(res, state?.redirectUrl, { error: { name, message }, - redirectUrl: `${baseUrl}/.backstage/error`, + apiUrl: `${baseUrl}/.backstage/error`, }); const redirectUrl = new URL(state.redirectUrl);