Reputation:
I'm a little bit stuck trying to understand OAuth flows. I'm currently using Spotify API, and I've used passportjs to authenticate users. The thing that I'm not understanding is how to do api calls from my app now that the user has been authenticated.
Here is the complete code of my app, but in this part, how can I access to the access_token to fetch playlists data?
app.get('/playlists', ensureAuth, async(req,res,next) => {
let playlists_url = `https://api.spotify.com/v1/users/${req.user.id}/playlists`;
res.render('playlists')
})
Because, as I was told, store the access token somewhere in this part
function(accessToken, refreshToken, expires_in, profile, done) {
process.nextTick(function(){
return done(null, profile);
})
}
isn't the best practice. But how do I recover the access token then?
Any help/comment is well recieved. Thanks!
Upvotes: 2
Views: 51
Reputation: 317
So as far as I can tell the part you pointed out as "not best practice" is the only possibility to save the accessToken
in your flow.
The second snippet is exactly where you would create a users account and save it to e.g. a Database. Doing that you would also save the accessToken
& refreshToken
.
Upvotes: 0