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 { IGlobalVariable } from '@automatisch/types';
import qs from 'qs';
const refreshToken = async ($: IGlobalVariable) => { const refreshToken = async ($: IGlobalVariable) => {
const stringifiedBody = qs.stringify({ const response = await $.http.post(
refresh_token: $.auth.data.refreshToken as string, 'https://accounts.spotify.com/api/token',
grant_type: 'refresh_token', null,
}); {
headers: {
const headers = {
Authorization: `Basic ${Buffer.from( Authorization: `Basic ${Buffer.from(
$.auth.data.clientId + ':' + $.auth.data.clientSecret $.auth.data.clientId + ':' + $.auth.data.clientSecret
).toString('base64')}`, ).toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}; },
params: {
const response = await $.http.post( refresh_token: $.auth.data.refreshToken as string,
'https://accounts.spotify.com/api/token', grant_type: 'refresh_token',
stringifiedBody, },
{ headers } additionalProperties: {
skipAddingAuthHeader: true
}
}
); );
await $.auth.set({ await $.auth.set({

View File

@@ -1,6 +1,8 @@
import { TBeforeRequest } from '@automatisch/types'; import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => { const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
if (requestConfig.additionalProperties?.skipAddingAuthHeader) return requestConfig;
if ($.auth.data?.accessToken) { if ($.auth.data?.accessToken) {
const authorizationHeader = `Bearer ${$.auth.data.accessToken}`; const authorizationHeader = `Bearer ${$.auth.data.accessToken}`;
requestConfig.headers.Authorization = authorizationHeader; requestConfig.headers.Authorization = authorizationHeader;