I am trying to authenticate Spotify API using the OAuth2.0 client credentials flow. Generally the flow is as follows:
const open = require('open')
responseType = 'token'
clientID = 'CLIENT_ID'
redirectURI = 'http%3A%2F%2Flocalhost%3A8888%2Fcallback'
scope = 'streaming+user-read-email+user-modify-playback-state+user-read-private+user-library-read+user-library-modify+user-read-currently-playing'
contentType = 'application/json'
params = {
'response_type' : responseType,
'client_id' : clientID,
'redirect_uri' : redirectURI,
'scope' : scope
}
headers = {
'Content-Type' : contentType
}
// send user to browser to grant data permissions
open(`https://accounts.spotify.com/en/authorize?response_type=${responseType}&client_id=${clientID}&redirect_uri=${redirectURI}&scope=${scope}&show_dialog=true`)
-- this part is fine, i have no issues sending user to browser to login and grant my app permission and the Express server i have listening on port 8888 lets me know when the callback pings with the response
http://localhost:8888/callback#authentication_token=2iais820zg...fh9IHkLDI&timeout=3600
-- this is what i am having problems with.here is my how i am handling the api callback in my Express server's /callback endpoint:
app.get('/callback', function (req, res) {
console.log('someone made a request!\n')
/// ////
console.log(req + '\n')
console.log(res + '\n')
/// ////
console.log(req.body)
res.json(req.body)
res.send('GET request to callback endpoint took you here')
res.end()
})
but the console output is as follows:
> server is listening on port 8888 ...
someone made a request!
[object Object]
[object Object]
{}
where everything is empty.
how can i access the URL parameters of the callback GET request? i have tried changing the handling from GET to POST as people have told me that a GET request doesn't contain params but the callback can't find the endpoint (bc it's not making a POST request..)
you should put the parameters into request body not in the header as you mentioned
to let you use req.body with no problem