diff --git a/src/app/lib/uasApi/getAuthHeader.ts b/src/app/lib/uasApi/getAuthHeader.ts deleted file mode 100644 index dc98fd2ddbf..00000000000 --- a/src/app/lib/uasApi/getAuthHeader.ts +++ /dev/null @@ -1,23 +0,0 @@ -import Cookie from 'js-cookie'; -import onClient from '#app/lib/utilities/onClient'; -import { getEnvConfig } from '../utilities/getEnvConfig'; - -const getAuthHeaders = (): Record => { - const cknsAtkn = onClient() ? Cookie.get('ckns_atkn') : undefined; - - const apiKey = getEnvConfig().SIMORGH_UAS_PUBLIC_API_KEY; - - if (!cknsAtkn || !apiKey) { - throw new Error('Missing authentication for UAS request'); - } - - const headers: Record = { - Authorization: `Bearer ${cknsAtkn}`, - 'X-Authentication-Provider': 'idv5', - 'X-API-Key': apiKey, - }; - - return headers; -}; - -export default getAuthHeaders; diff --git a/src/app/lib/uasApi/getAuthHeaders.ts b/src/app/lib/uasApi/getAuthHeaders.ts new file mode 100644 index 00000000000..3ece0cb8ed2 --- /dev/null +++ b/src/app/lib/uasApi/getAuthHeaders.ts @@ -0,0 +1,17 @@ +import { getEnvConfig } from '../utilities/getEnvConfig'; + +const getAuthHeaders = (): HeadersInit => { + const apiKey = getEnvConfig().SIMORGH_UAS_PUBLIC_API_KEY; + + if (!apiKey) { + throw new Error('Missing UAS public API key'); + } + + const headers: HeadersInit = { + 'X-API-Key': apiKey, + }; + + return headers; +}; + +export default getAuthHeaders; diff --git a/src/app/lib/uasApi/index.test.ts b/src/app/lib/uasApi/index.test.ts index d6f1e055373..a530ae7ab72 100644 --- a/src/app/lib/uasApi/index.test.ts +++ b/src/app/lib/uasApi/index.test.ts @@ -36,8 +36,6 @@ describe('uasApiRequest', () => { expect.objectContaining({ method: 'GET', headers: expect.objectContaining({ - Authorization: 'Bearer mocked-token', - 'X-Authentication-Provider': 'idv5', 'X-API-Key': 'mocked-api-key', }), }), @@ -63,8 +61,6 @@ describe('uasApiRequest', () => { expect.objectContaining({ method: 'POST', headers: expect.objectContaining({ - Authorization: 'Bearer mocked-token', - 'X-Authentication-Provider': 'idv5', 'X-API-Key': 'mocked-api-key', 'Content-Type': 'application/json', }), @@ -91,8 +87,6 @@ describe('uasApiRequest', () => { expect.objectContaining({ method: 'DELETE', headers: expect.objectContaining({ - Authorization: 'Bearer mocked-token', - 'X-Authentication-Provider': 'idv5', 'X-API-Key': 'mocked-api-key', }), }), @@ -121,23 +115,6 @@ describe('uasApiRequest', () => { ); }); - it('should throw an error when ckns_atkn cookie is missing', async () => { - // Mock the scenario where the ckns_atkn cookie is not in storage - (mockCookie.get as jest.Mock).mockReturnValue(undefined); - mockGetEnvConfig.mockReturnValue({ - SIMORGH_UAS_PUBLIC_API_KEY: 'mocked-api-key', - } as ReturnType); - - const activityType = 'favourites'; - - await expect(uasApiRequest('GET', activityType)).rejects.toThrow( - 'Missing authentication for UAS request', - ); - - // Verify that fetch was never called since authentication failed - expect(global.fetch).not.toHaveBeenCalled(); - }); - it('should throw an error when API key is missing', async () => { // Mock the scenario where the API key is not configured (mockCookie.get as jest.Mock).mockReturnValue('mocked-token'); @@ -148,7 +125,7 @@ describe('uasApiRequest', () => { const activityType = 'favourites'; await expect(uasApiRequest('GET', activityType)).rejects.toThrow( - 'Missing authentication for UAS request', + 'Missing UAS public API key', ); // Verify that fetch was never called since authentication failed diff --git a/src/app/lib/uasApi/index.ts b/src/app/lib/uasApi/index.ts index fe54cb289c4..cdb990374cd 100644 --- a/src/app/lib/uasApi/index.ts +++ b/src/app/lib/uasApi/index.ts @@ -1,5 +1,5 @@ import isLive from '#app/lib/utilities/isLive'; -import getAuthHeaders from './getAuthHeader'; +import getAuthHeaders from './getAuthHeaders'; import { activityTypes } from './uasUtility'; export type UasMethod = 'POST' | 'DELETE' | 'GET';