diff --git a/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterServiceFactory.ts b/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterServiceFactory.ts index f8ccdde780..0b79425e36 100644 --- a/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterServiceFactory.ts +++ b/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterServiceFactory.ts @@ -84,6 +84,14 @@ export const httpRouterServiceFactory = createServiceFactory( }, addAuthPolicy(policy: HttpRouterServiceAuthPolicy): void { credentialsBarrier.addAuthPolicy(policy); + if (policy.allow === 'user-cookie') { + // Endpoint that sets the cookie for the user + // TODO: Extract this to a separate createCookieAuthRefreshMiddleware function + router.get('/.backstage/v1-cookie', async (_, res) => { + const { expiresAt } = await httpAuth.issueUserCookie(res); + res.json({ expiresAt: expiresAt.toISOString() }); + }); + } }, }; }, diff --git a/plugins/auth-react/src/hooks/useCookieAuthRefresh/useCookieAuthRefresh.tsx b/plugins/auth-react/src/hooks/useCookieAuthRefresh/useCookieAuthRefresh.tsx index dfb13289db..45753d7460 100644 --- a/plugins/auth-react/src/hooks/useCookieAuthRefresh/useCookieAuthRefresh.tsx +++ b/plugins/auth-react/src/hooks/useCookieAuthRefresh/useCookieAuthRefresh.tsx @@ -31,13 +31,13 @@ import { ResponseError } from '@backstage/errors'; export function useCookieAuthRefresh(options: { // The plugin id used for discovering the API origin pluginId: string; - // The path used for calling the refresh cookie endpoint, default to '/cookie' + // The path used for calling the refresh cookie endpoint, default to '/.backstage/v1-cookie' path?: string; }): | { status: 'loading' } | { status: 'error'; error: Error; retry: () => void } | { status: 'success'; data: { expiresAt: string } } { - const { pluginId, path = '/cookie' } = options ?? {}; + const { pluginId, path = '/.backstage/v1-cookie' } = options ?? {}; const fetchApi = useApi(fetchApiRef); const discoveryApi = useApi(discoveryApiRef); diff --git a/plugins/techdocs-backend/src/service/router.ts b/plugins/techdocs-backend/src/service/router.ts index 3a2eb4eee6..b6f95d4e1b 100644 --- a/plugins/techdocs-backend/src/service/router.ts +++ b/plugins/techdocs-backend/src/service/router.ts @@ -322,12 +322,6 @@ export async function createRouter( // Route middleware which serves files from the storage set in the publisher. router.use('/static/docs', publisher.docsRouter()); - // Endpoint that sets the cookie for the user - router.get('/cookie', async (_, res) => { - const { expiresAt } = await httpAuth.issueUserCookie(res); - res.json({ expiresAt: expiresAt.toISOString() }); - }); - return router; }