cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

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: 

Re: dbx.auth not working / getAccessTokenFromCode giving 400 response?

dbx.auth not working / getAccessTokenFromCode giving 400 response?

bffy_smmmers
Explorer | Level 4
Go to solution

I'm trying to access the `getAccessTokenFromCode` method and I keep receiving a 400 error. On top of that, I can't seem to write the code and get it to work in the way it's written in the Auth example from the JavaScript SDK. `dbx.auth` does not work for me whether I construct an instance of Dropbox or DropboxAuth.


When i call `dbx.GetAccessTokenFromCode(redirectURI, code)`, I get a 400 response. I'm using the latest version (9.2.0). Furthermore, I read that `getAccessTokenFromCode` accepts null as a value in redirect uri as of version 5.0 and that doesn't work for me here either. Any help is so much appreciated.  Thanks! 

 

Example (Leaving a lot out since all I want to show is that token.result.refresh_token doesn't exist for me, just token.result.

const dbx = new Dropbox(config);

dbx.auth
.getAccessTokenFromCode(redirectUri, code)
.then(token => {
console.log(`Token Result:${JSON.stringify(token)}`);
dbx.auth.setRefreshToken(token.result.refresh_token);
dbx
.usersGetCurrentAccount()
.then(response => {
console.log('response', response);
})

 What I have to do is use the DropboxAuth class - which still doesn't work. (I'm using TypeScript, if it matters) 
const dbx = new DropboxAuth(config)

try {
const data = await dbx.getAccessTokenFromCode('some redirectURL',code)
} catch (err){
console.log(err.message)
}

 
12 Replies 12

Greg-DB
Dropbox Staff
Go to solution

That's correct, that parameter isn't currently implemented in the Dropbox JavaScript SDK, but I'll be sure to pass this along as a feature request. You can add it to the /oauth2/authorize URL in your app's own code though, by modifying the URL returned by getAuthenticationUrl.

bffy_smmmers
Explorer | Level 4
Go to solution

@Greg-DB Would you be able to expand on how that exactly gets done? Thanks! 

Greg-DB
Dropbox Staff
Go to solution

For example, where authUrl is the URL you got from getAuthenticationUrl, you can modify it like this:

var url = new URL(authUrl);
var urlParams = new URLSearchParams(url.search);
urlParams.set('force_reapprove', 'true');
url.search = urlParams;
console.log(url.href);
Need more support?