Skip to content

Commit

Permalink
feat(authentication): Support identity auth v3 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
osama-salman99 authored Nov 28, 2023
1 parent d2f3568 commit 982afdc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion core/src/authentication/Authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion core/src/constant/Authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion core/src/constant/Constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions core/test/authentication/Authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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')

Expand Down

0 comments on commit 982afdc

Please sign in to comment.