From 8c5080d2f49a8542b9613000d6954876f190e4a1 Mon Sep 17 00:00:00 2001 From: "paulius.valiunas" <66480813+paulius-valiunas@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:55:31 +0200 Subject: [PATCH] Fix Client Credentials authorization header --- packages/insomnia/src/network/basic-auth/get-header.ts | 5 ++--- packages/insomnia/src/network/o-auth-2/get-token.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/insomnia/src/network/basic-auth/get-header.ts b/packages/insomnia/src/network/basic-auth/get-header.ts index 4439aa96f..670bedde6 100644 --- a/packages/insomnia/src/network/basic-auth/get-header.ts +++ b/packages/insomnia/src/network/basic-auth/get-header.ts @@ -3,11 +3,10 @@ import type { RequestHeader } from '../../models/request'; export function getBasicAuthHeader( username?: string | null, password?: string | null, - encoding = 'utf8', + encoding: BufferEncoding = 'utf8', ) { const name = 'Authorization'; - const header = `${username || ''}:${password || ''}`; - // @ts-expect-error -- TSCONVERSION appears to be a genuine error + const header = `${username ?? ''}:${password ?? ''}`; const authString = Buffer.from(header, encoding).toString('base64'); const value = `Basic ${authString}`; const requestHeader: RequestHeader = { diff --git a/packages/insomnia/src/network/o-auth-2/get-token.ts b/packages/insomnia/src/network/o-auth-2/get-token.ts index 3a30eaa55..1bf82db1c 100644 --- a/packages/insomnia/src/network/o-auth-2/get-token.ts +++ b/packages/insomnia/src/network/o-auth-2/get-token.ts @@ -159,7 +159,7 @@ export const getOAuth2Token = async ( ...insertAuthKeyIf('client_secret', authentication.clientSecret), ]; } else { - headers.push(getBasicAuthHeader(authentication.clientId, authentication.clientSecret)); + headers.push(getBasicAuthHeader(encodeURIComponent(authentication.clientId ?? ''), encodeURIComponent(authentication.clientSecret ?? ''))); } const response = await sendAccessTokenRequest(requestId, authentication, params, headers);