Curious about A, B, C, and D drives? Learn what they mean and how to use them effectively with Dropbox in this handy guide! - check it out now!

Forum Discussion

TheKrominator's avatar
TheKrominator
Explorer | Level 3
5 years ago

Invalid grant type during authorization with dropbox-oauth2

I am using the passport authenticate with 'dropbox-oauth2' to get my login token and receive my Bearer. This worked fine until about midday yesterday when it started sending me this : error_description: 'code has already been used',
error: 'invalid_grant'

 

To get the Dropbox authorization screen, I use this :

app.get('/dropboxLogin', passport.authenticate('dropbox-oauth2'));

app.get('/auth/dropbox/callback',
passport.authenticate('dropbox-oauth2', { failureRedirect: '/', params:{'response_type':'token'} }),
function(req, res)
{
// Successful authentication, redirect home.
res.render('index', { title:'Dropbox Login', body:res});
});

 

Once I've received my token I run : axios({
method : 'post',
url : 'https://api.dropboxapi.com/oauth2/token',
params :
{
code : request.body.code,
grant_type : 'authorization_code',
redirect_uri : 'http://localhost:9000/callback',
client_id : '##############',
client_secret : '##############'
}
})

 

Thats when I get the error. 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Dropbox OAuth 2 authorization codes can each only be used once. (You should just use the authorization code once, but you can store and re-use the resulting access token.)

     

    The "code has already been used" error message should just indicate that the authorization code you're supplying has already been used. I just gave the flow a try and it seems to be working as expected for me.

     

    Can you double check you're not accidentally re-using the authorization code, or perhaps accidentally issuing the /oauth2/token request more than once?

    • TheKrominator's avatar
      TheKrominator
      Explorer | Level 3

      I've learned that my router file was no longer being called. This caused my '/' command to not run and would return that strange error. Now, that I've reconnected my authorization routes, it is running correctly again.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,962 PostsLatest Activity: 2 years ago
356 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!