Is it possible to have the redirect_uri contain a specific port?

For example: example.com:8080

Assuming that example.com is my registered domain, is the 8080 allowed? I have tried to put it as part of my OAuth Domain, but get this error:

OAuth Domain should not contain protocol or port

If I leave the port off, it does attempt to redirect properly, but my application will not be living on my main web server.


2 Answers 2


You got that error because you set the OAuth Domain like example.com:8080, not the redirect_uri. That's not how you configure non-standard ports; see below.

The redirect uri, with port, feature now works (it didn't once upon a time).

To use, adjust your app settings:

  1. Go to https://stackapps.com/apps/oauth and click on your desired app.
  2. Click the "Edit This App" button near the bottom of the page.
  3. For OAuth Domain, enter just your domain without any protocol nor port.
    EG: example.com
  4. For Application Website, Enter a valid appropriate page on that domain, with port.
    EG: http://example.com:8080/allaboutthefooapp/
  5. Since you are using your own server, leave Enable Client Side OAuth Flow unchecked.
  6. Since you are using your own server, you normally want Disable Desktop Application OAuth Redirect Uri checked.
  7. Save the changes.

Then in your app, perform the explicit OAuth 2.0 flow with API interactions like the following example:

  1. Send the user to: https://stackexchange.com/oauth?client_id=yourID&scope=private_info&redirect_uri=http://example.com:8080/yourAuthPage
  2. If the user authorizes your app, your server will see the access code in the URL parameters.
    EG: http://example.com:8080/yourAuthPage/?code=Wu*pvlTxhN0fDpaqu17Z9w))
  3. Take the code from the previous step and POST to https://stackoverflow.com/oauth/access_token with the following form parameters:
    1. client_id: Your app's id. EG: 1633
    2. client_secret: Your app's secret code. EG: 2VLux8e4mxSSZkYhG3doIQ((
    3. code: The code from step 2. EG: Wu*pvlTxhN0fDpaqu17Z9w))
    4. redirect_uri: Must be the same as from step 1.
      EG: http://example.com:8080/yourAuthPage
  4. The access_token will be in the body of the resulting page. EG: access_token=ag*Vsxxxxuapy(batHWUcw))&expires=86400

Remove the protocol and it should work.

On my localhost, I am testing OAuth on a random port and it works fine, while the App setting for redirect_uri is just localhost.

  • @BrockAdams is localhost still a special case? Is this documented anywhere?
    – Alex
    Commented Apr 7, 2018 at 16:22
  • @Alex, Not really and no. But the good news is that OAuth now works for servers running nonstandard ports. See my answer. Commented Apr 8, 2018 at 1:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .