fix(spotify): do not override auth header on refresh token

This commit is contained in:
Ali BARIN
2023-03-22 20:38:27 +00:00
parent 8acd7b03ed
commit 6d3bec8518
2 changed files with 18 additions and 15 deletions

View File

@@ -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({

View File

@@ -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;