Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require("axios");
- const spotify = require("./credentials");
- const getAccessToken = (req, res, next) => {
- const { code } = req.query;
- const data = {
- grant_type: "authorization_code",
- code,
- ...spotify
- };
- axios({
- url: 'https://accounts.spotify.com/api/token',
- method: 'post',
- params: {
- grant_type: 'client_credentials'
- },
- headers: {
- 'Accept':'application/json',
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- auth: {
- username: spotify.client_id,
- password: spotify.client_secret
- }
- }).then(res => {
- req.credentials = res.data
- next()
- }).catch(function(error) {
- console.log(error)
- });
- };
- module.exports = getAccessToken;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement