cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I set the Redirect URI port number?

Jaihoon_Ahn
Explorer | Level 3

Dropbox You have configured a Redirect URI for OAuth2 authentication.

 

- http://127.0.0.1
- http://127.0.0.1:port

 

I have coded the following code in C #.

----------------------------------------------------------

string redirectURI = "http://127.0.0.1:56207";
string requestURI = "https://www.dropbox.com/oauth2/authorize?response_type=token&redirect_uri=http://127.0.0.1:56207&cli...";

 

HttpListener httpListener = new HttpListener();
httpListener.Prefixes.Add("http://127.0.0.1:56207/");
httpListener.Start();

 

System.Diagnostics.Process.Start(requestURI);

----------------------------------------------------------

 

The result is Error (400).

 

 

err400.png

 

What is wrong with it?

 

6 Replies 6

Re: How do I set the Redirect URI port number?

Dropboxer
Dropboxer

You can use an OAuth 2 redirect URI including a port number, but it will still need to exactly match one of the OAuth 2 redirect URIs that you previously registered, including the port and path. If they don't match exactly, you'll get the error above.

 

So, first register the exact OAuth 2 redirect URI on the App Console (using the port number, not the string "port") and then use that exact string in the redirect_uri URL parameter.

 

For example, you're passing "http://127.0.0.1:56207" as the redirect_uri value, so you'll need to register "http://127.0.0.1:56207" exactly on the App Console.

 

I just tried this and it is working properly for me. If it's not working for you, please share a screenshot of the OAuth 2 redirect URIs registered for your app on the App Console as well as a screenshot of the error page you're getting, including the full URL.

Re: How do I set the Redirect URI port number?

Jaihoon_Ahn
Explorer | Level 3

Answer Well received.
When the fixed port number is used according to the reply contents, it works correctly.

 

Fixing the port number is probably a problem.
You specified port 56207 in the app console as 'http://127.0.0.1:56207'.
OAuth2 authentication is expected to fail if the 56207 port is blocked on the PC or another application is preempting it.

 

So, when redirecting to Localhost, I want to specify port number which is not used in PC.
I know that 'Google' is not limited to Localhost.

Re: How do I set the Redirect URI port number?

Dropboxer
Dropboxer
You can choose whatever redirect URI/port you want, but whatever you do choose, you need to pre-register it on the App Console.

Re: How do I set the Redirect URI port number?

Jaihoon_Ahn
Explorer | Level 3

Additional questions.


Let's try randomly selecting the port number from "50000 ~ 51000".

AppConsole settings should add 1000 or more as below.

 

http://127.0.0.1:50000
http://127.0.0.1:50001
http://127.0.0.1:50002
http://127.0.0.1:50003
... more ... more ...
http://127.0.0.1:50998
http://127.0.0.1:50999
http://127.0.0.1:51000


Is there a limit to the number of Redirect URIs that can be set in AppConsole?

Re: How do I set the Redirect URI port number?

Dropboxer
Dropboxer
There isn't a limit on the number of redirect URIs you can add, but I can't promise that won't change in the future.

Re: How do I set the Redirect URI port number?

rshvets New member | Level 2
New member | Level 2

yes, fixed port number is really a headache.

 

And you are right about Google. For some reason Dropbox limits their redirect URIs when Google allows to define that URI dynamically.

 

Instead of letting my web server find out which port is available I have to loop over fixed number of ports and try to run that server using first avaialble port. It is really uncomfortable.

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?