Take Your Search Game to the Next Level with Dropbox Dash  🚀✨ Curious how it works? Ask us here! 

Forum Discussion

Jaihoon_Ahn's avatar
Jaihoon_Ahn
Explorer | Level 3
8 years ago

How do I set the Redirect URI port number?

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&client_id=4tb5otn53umkiro&state=W1LlGGzWZXqpv68QU-d3wrGbOFviArFeVyvdXQBX7u4";

 

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).

 

 

 

What is wrong with it?

 

6 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    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.

  • Jaihoon_Ahn's avatar
    Jaihoon_Ahn
    Explorer | Level 3
    8 years ago

    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.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago
    You can choose whatever redirect URI/port you want, but whatever you do choose, you need to pre-register it on the App Console.
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago
    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.
  • rshvets's avatar
    rshvets
    New member | Level 2
    8 years ago

    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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,011 PostsLatest Activity: 21 hours ago
394 Following

If 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!