# Discourse redirects to the OAuth server after loading \`/?authComplete=true\`

**URL:** <https://meta.discourse.org/t/discourse-redirects-to-the-oauth-server-after-loading-authcomplete-true/115973>\
**Category:** SSO\
**Created:** [25.Апрель.2019 15:51:00 UTC](https://meta.discourse.org/t/discourse-redirects-to-the-oauth-server-after-loading-authcomplete-true/115973 "2019-04-25T15:51:00Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![ryancey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryancey/32/99309_2.png) [@ryancey](https://meta.discourse.org/u/ryancey)\
**Post date:** [25.Апрель.2019 15:51:00 UTC](https://meta.discourse.org/t/discourse-redirects-to-the-oauth-server-after-loading-authcomplete-true/115973/1 "2019-04-25T15:51:00Z")

</div>

The flow is a bit complex. OAuth is the only allowed login on the Discourse instance. The whole idea is for the user to land back on the site they were before they were asked to create an account on the OAuth server.

It goes like this:

- User clicks `Login`
- Thanks to a [custom code snippet](https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123/6), it goes directly to the (custom) OAuth server login page
- User clicks `Create an account` and creates an account on the OAuth server
- A confirmation e-mail is sent

Meanwhile, the OAuth server stores that when this particular e-mail is confirmed, and as soon as the user logs in again, it must redirect them to `https://[discourse-server]/auth/oauth2_basic` to automatically initiate a login process.

The issue is here.

- When the user clicks the OAuth server confirmation link **in the same browser session** (used from the first step)

- When the user clicks the OAuth server confirmation link **in a new browser session**

* * *

A screenshot to go with the text…

 ![45](https://global.discourse-cdn.com/meta/original/3X/c/4/c4622aca1e207880f9338df59d3504c3b820ff78.png)

Text to go with the screenshot…

- #1 | The user has just confirmed its e-mail and successfully signs in, redirected to its profile page
- #2 | The profile page is where the custom redirection I was talking about is taking place, so the user is redirected to `https://[discourse-server]/auth/oauth2_basic`
- #3 | Discourse then redirects the user back to the OAuth server to initiate the login process
- #4 | OAuth authorization
- #5 | Discourse callback, redirecting the user to `/?authComplete=true`
- #6 | Bunch of assets loading (filtered in the devtools)
- **#7 | Boom** , out of nowhere, the user is redirected to the OAuth server root path
- #8 | … then redirected to its profile since they’re already logged in

* * *

So I’m guessing the extra redirect has something to do with a session-based storage.

Can someone point me to an area of the Discourse codebase where something like this would occur?

I’m [already digging](https://github.com/discourse/discourse/search?q=authComplete&unscoped_q=authComplete) but some help would be appreciated. Thanks a lot.

---

_[View the full topic](https://meta.discourse.org/t/discourse-redirects-to-the-oauth-server-after-loading-authcomplete-true/115973)._
