From 6d3bec8518e77a6989da329f1b796997c00b6e2a Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Wed, 22 Mar 2023 20:38:27 +0000 Subject: [PATCH] fix(spotify): do not override auth header on refresh token --- .../src/apps/spotify/auth/refresh-token.ts | 31 ++++++++++--------- .../apps/spotify/common/add-auth-header.ts | 2 ++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/apps/spotify/auth/refresh-token.ts b/packages/backend/src/apps/spotify/auth/refresh-token.ts index 11824599..dc20820a 100644 --- a/packages/backend/src/apps/spotify/auth/refresh-token.ts +++ b/packages/backend/src/apps/spotify/auth/refresh-token.ts @@ -1,23 +1,24 @@ import { IGlobalVariable } from '@automatisch/types'; -import qs from 'qs'; const refreshToken = async ($: IGlobalVariable) => { - const stringifiedBody = qs.stringify({ - refresh_token: $.auth.data.refreshToken as string, - grant_type: 'refresh_token', - }); - - const headers = { - Authorization: `Basic ${Buffer.from( - $.auth.data.clientId + ':' + $.auth.data.clientSecret - ).toString('base64')}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }; - const response = await $.http.post( 'https://accounts.spotify.com/api/token', - stringifiedBody, - { headers } + null, + { + headers: { + Authorization: `Basic ${Buffer.from( + $.auth.data.clientId + ':' + $.auth.data.clientSecret + ).toString('base64')}`, + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + refresh_token: $.auth.data.refreshToken as string, + grant_type: 'refresh_token', + }, + additionalProperties: { + skipAddingAuthHeader: true + } + } ); await $.auth.set({ diff --git a/packages/backend/src/apps/spotify/common/add-auth-header.ts b/packages/backend/src/apps/spotify/common/add-auth-header.ts index d650c915..d16f394f 100644 --- a/packages/backend/src/apps/spotify/common/add-auth-header.ts +++ b/packages/backend/src/apps/spotify/common/add-auth-header.ts @@ -1,6 +1,8 @@ import { TBeforeRequest } from '@automatisch/types'; const addAuthHeader: TBeforeRequest = ($, requestConfig) => { + if (requestConfig.additionalProperties?.skipAddingAuthHeader) return requestConfig; + if ($.auth.data?.accessToken) { const authorizationHeader = `Bearer ${$.auth.data.accessToken}`; requestConfig.headers.Authorization = authorizationHeader;