cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Invalid grant type during authorization with dropbox-oauth2

Highlighted

Invalid grant type during authorization with dropbox-oauth2

Explorer | Level 3

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. 

2 Replies 2
Highlighted

Re: Invalid grant type during authorization with dropbox-oauth2

Dropboxer

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?

Highlighted

Re: Invalid grant type during authorization with dropbox-oauth2

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.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?