You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
pvr325i
9 months agoExplorer | Level 3
Next.js 14 oAuth 2.0 authorization flow redirect 401 error
Hi first time poster here. I've got the authorization flow successfully integrated up to the point where the callback url appears in the browser address window, ie: http://localhost:3000/api/dr...
Greg-DB
Dropbox Staff
pvr325i Здравко is correct; based on that output, that error is coming from your http://localhost:3000 server, so you'd need to check on what it is doing on its /api/dropboxcallback page. For instance, check your server logs and debug the code it is running.
pvr325i
9 months agoExplorer | Level 3
Hi @Greg-DB and @Здравко
Thank you both for your replies.
This is the first time I am implementing the Dropbox oauth 2.0 authorization flow so I apologise if my understanding or language is not precise.
What I am trying to achieve is for the app to interact with a user’s Dropbox account on the user’s behalf. I understand that an access token from Dropbox is required by the app in order for the app to achieve this. My understanding is that this access token is produced as a consequence of completing the Dropbox oauth 2.0 authorization flow.
If my understanding is not correct, I would be grateful if you were able to correct it.
Leaving aside for the moment whether my understanding is correct, what I have been able to achieve so far is the following:
- The user indicates they want to allow the app to interact with the user’s Dropbox account on their behalf by clicking a button -> ‘Allow Dropbox access’
- Upon clicking the button, the page is rerouted to `https://www.dropbox.com/oauth2/authorize?client_id=${process.env.NEXT_PUBLIC_DROPBOX_APP_KEY}&response_type=code&redirect_uri=${process.env.NEXT_PUBLIC_DROPBOX_REDIRECT_URI}&access_token_type=online`;
- The Dropbox authorization flow appears. The user is given a choice to click on the ‘Continue’ and ’Allow’ buttons on the ‘Before you connect to this app…’ and ‘[name of app] would like to:’ pages respectively.
- If the user clicks on both of these buttons, the Dropbox authorization flow disappears and the browser window goes blank.
- A url similar to the following ‘http://localhost:3000/api/dropboxcallback?code=Ws4_UVwyTaIAAAAAAAAu9Cdym8LTtUw6RUcHUAP_pQk’ appears in the browser address bar (Callback Url)
- A GET 401 Unauthorized message appears in the browser console tab
- A 401 error appears on the second line in the browser network tab
- If the Callback Url is executed manually, the logic located in the api/dropboxcallback api route executes successfully and an access token is created.
My question is: why is the Callback Url not executed automatically?
@Greg-DB you say I ‘need to check on what it is doing on its /api/dropboxcallback page’ – this page executes properly and successfully if the Callback Url is executed manually. This page does not appear to be being ‘reached’ once the Dropbox authorization flow has finished.
So therefore, why is this so? Why is being treated as ‘unauthorized’? If the answer to this question can be determined, then perhaps this will lead to the entire authorization flow executing automatically.
If you were able to provide any assistance as to why the Callback Url is being regarded as unauthorized, I would be very grateful.
Although I made a reference to ‘state’ in my original post, I believe I understand the purpose behind this better now and do not believe it forms part of the larger question as to why the Callback Url is being treated as unauthorized. However, I am very happy to be corrected.
I am very grateful for any assistance.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,888 PostsLatest Activity: 17 hours agoIf 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!