feat: add refresh token for spotify
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import generateAuthUrl from './generate-auth-url';
|
import generateAuthUrl from './generate-auth-url';
|
||||||
import verifyCredentials from './verify-credentials';
|
import verifyCredentials from './verify-credentials';
|
||||||
import isStillVerified from './is-still-verified';
|
import isStillVerified from './is-still-verified';
|
||||||
|
import refreshToken from './refresh-token';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fields: [
|
fields: [
|
||||||
@@ -39,6 +40,7 @@ export default {
|
|||||||
clickToCopy: false,
|
clickToCopy: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
refreshToken,
|
||||||
generateAuthUrl,
|
generateAuthUrl,
|
||||||
verifyCredentials,
|
verifyCredentials,
|
||||||
isStillVerified,
|
isStillVerified,
|
||||||
|
30
packages/backend/src/apps/spotify/auth/refresh-token.ts
Normal file
30
packages/backend/src/apps/spotify/auth/refresh-token.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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 }
|
||||||
|
);
|
||||||
|
|
||||||
|
await $.auth.set({
|
||||||
|
accessToken: response.data.access_token,
|
||||||
|
expiresIn: response.data.expires_in,
|
||||||
|
tokenType: response.data.token_type,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default refreshToken;
|
Reference in New Issue
Block a user