Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
2,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. const axios = require("axios");
  2. const spotify = require("./credentials");
  3.  
  4. const getAccessToken = (req, res, next) => {
  5. const { code } = req.query;
  6.  
  7. const data = {
  8. grant_type: "authorization_code",
  9. code,
  10. ...spotify
  11. };
  12.  
  13. axios({
  14. url: 'https://accounts.spotify.com/api/token',
  15. method: 'post',
  16. params: {
  17. grant_type: 'client_credentials'
  18. },
  19. headers: {
  20. 'Accept':'application/json',
  21. 'Content-Type': 'application/x-www-form-urlencoded'
  22. },
  23. auth: {
  24. username: spotify.client_id,
  25. password: spotify.client_secret
  26. }
  27. }).then(res => {
  28. req.credentials = res.data
  29. next()
  30. }).catch(function(error) {
  31. console.log(error)
  32. });
  33. };
  34.  
  35. module.exports = getAccessToken;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement