fix(spotify): do not override auth header on refresh token
This commit is contained in:
@@ -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({
|
|
||||||
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(
|
const response = await $.http.post(
|
||||||
'https://accounts.spotify.com/api/token',
|
'https://accounts.spotify.com/api/token',
|
||||||
stringifiedBody,
|
null,
|
||||||
{ headers }
|
{
|
||||||
|
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({
|
await $.auth.set({
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user