1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-07-06 19:00:50 +00:00
Files
musix-oss/src/funcs/getSpotifyKey.js
2024-02-10 09:33:59 +02:00

28 lines
1004 B
JavaScript

module.exports = async function (client) {
const request = require("request");
const refresh_token = client.config.spotify_refresh_token;
const authOptions = {
url: "https://accounts.spotify.com/api/token",
headers: {
Authorization: "Basic " +
new Buffer(client.config.spotify_client_id + ":" + client.config.spotify_client_secret).toString("base64"),
},
form: {
grant_type: "refresh_token",
refresh_token: refresh_token,
},
json: true,
};
request.post(authOptions, function (error, response, body) {
if (!error && response.statusCode === 200) {
client.spotify.setAccessToken(body.access_token);
client.config.spotify_access_key = body.access_token
if (client.config.devMode) console.log("- Spotify access token set -");
} else {
console.log("An error occured whilst getting spotify access key");
}
});
};