Announcements
Do you have an idea for Dropbox Paper? Share it with us here!

Javascript SDK to authorize user and get access token

Helpful | Level 5

Hi,

I am trying to get access token after Autharization. 

So on button click I redirect user to

 https://www.dropbox.com/oauth2/authorize?client_id=<APP_KEY>&response_type=code 

So user goes through the steps and authorize the app but it goes to a page like this II

image.png

I use Window.open with redirect url.

window.open(url,redirectURL );

I have a feeling I am not constructing redirect url properly. Can you please provide me with an example of window.open with proper url?

What am I doing wrong here?

1 Reply

Re: Javascript SDK to authorize user and get access token

Dropboxer

If you're using the official Dropbox API v2 JavaScript to integrate with Dropbox in a JavaScript app, you should use the supplied 'getAuthenticationUrl' method to build your authorization URL, which will contain whatever redirect URI value you supply. There's a working auth example included with the SDK here. (Instructions for running the examples can be found here.)

On this line, you call the getAuthenticationUrl method, supplying what you want your redirect URI to be. It gives back the full /oauth2/authorize URL, which is where you should send the user. In the example it does so by giving them a link set to that URL so they can click on it. I expect you can alternatively just pass it to window.open though. That would look like:

window.open(dbx.getAuthenticationUrl(redirectUri));

Once the user authorizes the app, Dropbox will redirect them to the specified redirect URI. In the example, the access token is retrieved from the URL fragment here.

Reply
Loading...
API Support

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about API Support.

Or, search our Help Center for even more.

Who's talking
Top contributors to this post