From 982afdc75d4ba2699b7d1cbafb9e9c0a6e0bb62c Mon Sep 17 00:00:00 2001 From: Osama Salman Date: Tue, 28 Nov 2023 13:05:18 +0300 Subject: [PATCH] feat(authentication): Support identity auth v3 (#138) --- core/src/authentication/Authenticator.ts | 6 +++++- core/src/constant/Authentication.ts | 4 +++- core/src/constant/Constant.ts | 2 +- core/test/authentication/Authentication.test.ts | 5 +++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/src/authentication/Authenticator.ts b/core/src/authentication/Authenticator.ts index 9b18ebf6..43538fe1 100644 --- a/core/src/authentication/Authenticator.ts +++ b/core/src/authentication/Authenticator.ts @@ -84,7 +84,11 @@ class Authenticator { method: Constant.POST, url: configurations.authEndpoint, headers: { - 'User-Agent': configurations.userAgent + 'User-Agent': configurations.userAgent, + 'Content-Type': Authentication.APPLICATION_FORM_URL_ENCODED + }, + params: { + grant_type: Authentication.CLIENT_CREDENTIALS }, auth: { username: configurations.key, diff --git a/core/src/constant/Authentication.ts b/core/src/constant/Authentication.ts index 797ac706..e4c2e20c 100644 --- a/core/src/constant/Authentication.ts +++ b/core/src/constant/Authentication.ts @@ -25,5 +25,7 @@ export const Authentication = { BEARER: 'Bearer', AUTHORIZATION: 'Authorization', USERNAME: 'username', - PASSWORD: 'password' + PASSWORD: 'password', + CLIENT_CREDENTIALS: 'client_credentials', + APPLICATION_FORM_URL_ENCODED: 'application/x-www-form-urlencoded' } as const diff --git a/core/src/constant/Constant.ts b/core/src/constant/Constant.ts index 9158b4a1..b70aada1 100644 --- a/core/src/constant/Constant.ts +++ b/core/src/constant/Constant.ts @@ -20,7 +20,7 @@ export const Constant = { ENDPOINT: 'https://api.expediagroup.com/', - AUTH_ENDPOINT: 'https://api.expediagroup.com/identity/oauth2/v2/token/', + AUTH_ENDPOINT: 'https://api.expediagroup.com/identity/oauth2/v3/token/', TEN_SECONDS_IN_MILLIS: 10_000, POST: 'POST', AUTHORIZATION: 'Authorization' diff --git a/core/test/authentication/Authentication.test.ts b/core/test/authentication/Authentication.test.ts index a7d3acc9..51f0d0e5 100644 --- a/core/test/authentication/Authentication.test.ts +++ b/core/test/authentication/Authentication.test.ts @@ -3,6 +3,7 @@ import { Constant } from '../constant/Constant' import { TestClient } from '../helper/TestClient' import { StatusCode } from '../constant/StatusCode' import { ExpediaGroupAuthError } from '../../src/model/error/service/ExpediaGroupAuthError' +import { Authentication } from '../../src/constant/Authentication' describe('Authentication', function () { it('should send an authentication request when token is expired', async function () { @@ -18,6 +19,10 @@ describe('Authentication', function () { expect(response.status).toEqual(StatusCode.OK) expect(response.data).toEqual(Constant.DATA) + expect(client.mockAdapter.history.post.length).toEqual(1) + expect(client.mockAdapter.history.post[0].headers?.['Content-Type']).toEqual(Authentication.APPLICATION_FORM_URL_ENCODED) + expect(client.mockAdapter.history.post[0].params?.grant_type).toEqual(Authentication.CLIENT_CREDENTIALS) + expect(client.mockAdapter.history.get.length).toEqual(1) expect(client.mockAdapter.history.get[0].headers?.Authorization).toEqual('Bearer token')