# Login redirect URIs redirecting to Local Host

**URL:** <https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442>\
**Category:** Questions\
**Created:** [August 8, 2020, 2:22am UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442 "2020-08-08T02:22:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rocki](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@Rocki](https://devforum.okta.com/u/Rocki)\
**Post date:** [August 8, 2020, 2:22am UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/1 "2020-08-08T02:22:42Z")

</div>

Hi, recently placed by Web App into production and for some reason the Login and Logout URl’s are all pointing to localhost, instead of the domain name. I don’t know why or what I am doing wrong

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/e/ef76846f5a8a252a9b6917adc3d397752712e367.png)  
These are the General settings, which I think I have done correctly. When running the node app locally, it works perfectly.

However when I uploaded the app onto a web server and ran it on nginx with a reverse proxy to port 3000. things started going wrong. I don’t know if this effected it?

Now when I try to login, the callback goes to ’ [http://localhost:3000/authorization-code/callback](http://localhost:3000/authorization-code/callback)? ’

![image](https://global.discourse-cdn.com/oktadev/original/2X/5/5be721e1afdfa34d7356b3dac5fceb2424d15411.png)

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![vijet](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/vijet/32/245_2.png) [@vijet](https://devforum.okta.com/u/vijet)\
**Post date:** [August 8, 2020, 5:14am UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/2 "2020-08-08T05:14:00Z")

</div>

Hi @Rocki,

The default redirect URI for the ExpressOIDC module is `{appBaseUrl}/authorization-code/callback`  
In your case, when you’re running locally, it’s [http://localhost:3000/authorization-code/callback](http://localhost:3000/authorization-code/callback) which looks correct.  
But when you deploy it to production server, it’s redirected to [https://yourDomain.com/authorization-code/callback](https://yourDomain.com/authorization-code/callback), provided that you’ve updated your `appBaseUrl` to [https://yourDomain.com](https://yourDomain.com)

Looking at your code (assuming it’s your production code), I see that `appBaseUrl` isn’t set correctly. It should be set to the domain of your server.  
And in the Okta Admin Application settings, replace `https://{domain}/authorization-code/callback` with the right value for your domain (something like [https://yourDomain.com/authorization-code/callback](https://yourDomain.com/authorization-code/callback))

You can see more configuration for ExpressOIDC middleware [here](https://github.com/okta/okta-oidc-js/tree/master/packages/oidc-middleware#expressoidc-api)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Rocki](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@Rocki](https://devforum.okta.com/u/Rocki)\
**Post date:** [August 8, 2020, 1:41pm UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/3 "2020-08-08T13:41:36Z")

</div>

Hi @vijet,

Thanks for the quick reply!

My appBaseUrl i think is set correctly, and so are the Otka Admin Settings, it’s just I replaced the URL with {domain} for the purposes of uploading it onto here. But its been set to this, which is the domain,

![image](https://global.discourse-cdn.com/oktadev/original/2X/7/7c087ed420853432467ca7e2067f99dacaa83d37.png)

Funnily enough, when the appBaseUrl is set to the production servers domain. The production server uses the localhost call back. So after logging using the sign in page this happens:

![image](https://global.discourse-cdn.com/oktadev/original/2X/e/eae3f2e798937036264789c7e48a04adff7c53e9.png)

But when running this locally, with the very same settings and code this happens:

![image](https://global.discourse-cdn.com/oktadev/original/2X/1/167be2f93620e5d3ba87a16e37b463cc8fb5cb08.png)

Its a very strange interaction that’s happening.

Both the domain and localhost are listed as trusted origins as well, so im really confused as to why this is happening.

These are my Otka Settings, without hiding the domain:

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/9/9388d26995db77f86f0d5fa4c97ecf477d1da927.png)  
Sorry for the confusion before!

---

<div class="post-metadata">

**Author:** ![phi1ipp](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@phi1ipp](https://devforum.okta.com/u/phi1ipp)\
**Post date:** [August 8, 2020, 2:20pm UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/4 "2020-08-08T14:20:19Z")

</div>

Try to provide `redirect_uri` explicitly in your OIDC config

```
const oidc = new ExpressOIDC({
...
redirect_uri: 'http://{your server and host}/authorization-code/callback',
```

---

<div class="post-metadata">

**Author:** ![Rocki](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@Rocki](https://devforum.okta.com/u/Rocki)\
**Post date:** [August 8, 2020, 3:21pm UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/5 "2020-08-08T15:21:04Z")

</div>

Hi @phi1ipp

Thanks for your reply!

I added that in and tried that:  
 ![image](https://global.discourse-cdn.com/oktadev/original/2X/d/dd4e3a675fbdbf47268f211f1e33c371347046d1.png)

But I still get the same result unfortunately

![image](https://global.discourse-cdn.com/oktadev/original/2X/8/8402b0772d57c75de9c8adc3b31f5ae0695e7916.png)

---

<div class="post-metadata">

**Author:** ![phi1ipp](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@phi1ipp](https://devforum.okta.com/u/phi1ipp)\
**Post date:** [August 9, 2020, 2:49am UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/6 "2020-08-09T02:49:21Z")

</div>

Well, well, well… I didn’t expect that from Okta 🙂

So change your parameter name to `loginRedirectUri` please, it should help.

---

<div class="post-metadata">

**Author:** ![Rocki](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@Rocki](https://devforum.okta.com/u/Rocki)\
**Post date:** [August 9, 2020, 4:59am UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/7 "2020-08-09T04:59:01Z")

</div>

Still got the same result unfortunately 😕 .Should I try configure a callback inside the routes parameter?  
 ![image](https://global.discourse-cdn.com/oktadev/original/2X/3/3bd6af63900618a783b8c8bb0fb80cc6a446cd5f.png)  
 ![image](https://global.discourse-cdn.com/oktadev/original/2X/d/dd23a38958f3092b7b7fa1aa5952c9cdde902e19.png)

Iv been stuck on this for a week now and I really have no idea what I’m doing wrong

---

<div class="post-metadata">

**Author:** ![phi1ipp](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@phi1ipp](https://devforum.okta.com/u/phi1ipp)\
**Post date:** [August 9, 2020, 4:10pm UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/8 "2020-08-09T16:10:20Z")

</div>

At this point I’d ask, are you sure that you are hitting your application?! This is all really strange. Is there a chance that your reverse proxy can do rewrite/reroute by any chance? Can you try to test directly hitting your application?

---

<div class="post-metadata">

**Author:** ![Rocki](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@Rocki](https://devforum.okta.com/u/Rocki)\
**Post date:** [August 20, 2020, 10:41pm UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/10 "2020-08-20T22:41:59Z")

</div>

@phi1ipp Fixed it! It was my server config. Just for future reference for anyone that might have the same problem.

Changed the settings to this instead:

proxy\_set\_header X-Forwarded-For $remote\_addr;  
proxy\_set\_header Host $http\_host;  
proxy\_pass [http://192.168.43.31:5000](http://192.168.43.31:5000);

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [January 26, 2021, 1:36am UTC](https://devforum.okta.com/t/login-redirect-uris-redirecting-to-local-host/10442/12 "2021-01-26T01:36:32Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
