# Redirect to requested URL after SSO

**URL:** https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820
**Category:** Bug
**Created:** [4월 22, 2015, 3:46오전 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820 "2015-04-22T03:46:45Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![casey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/casey/32/115495_2.png) [@casey](https://meta.discourse.org/u/casey)
#### Post date: [4월 22, 2015, 3:46오전 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/1 "2015-04-22T03:46:45Z")

</div>

## The Scenario:

We have a private, login required, Discourse installation that is relying on an external php/CodeIgniter site for SSO.  
SSO is working to sign in users just fine.

## The Problem:

When someone tries to hit a URL on the private Discourse site they’re redirected to the SSO login and hence the login form on the external site immediately.  
After login they’re then directed to the root of the Discourse site, **not the originally requested URL**.  
I’ve tried getting the referring url at the SSO endpoint but `$_SERVER['HTTP_REFERER'];` is empty.

Am I missing something that will allow me to send them back to the originally requested URL on the Discourse site?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [4월 22, 2015, 4:19오전 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/2 "2015-04-22T04:19:52Z")

</div>

I know @techapj fixed this for regular login. Not sure what the state is for SSO, perhaps you can check it and advise Arpit?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [4월 22, 2015, 4:31오전 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/3 "2015-04-22T04:31:08Z")

</div>

the protocol allows you to specify a return url. it works fine in plenty of spots.

---

<div class="post-metadata">

### Author: ![AdamCapriola](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamcapriola/32/5192_2.png) [@AdamCapriola](https://meta.discourse.org/u/AdamCapriola)
#### Post date: [4월 28, 2015, 7:21오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/4 "2015-04-28T19:21:31Z")

</div>

I just ran into this issue too (users are redirected to root and not originally requested URL).

When “login required” is off the redirect works as expected … but I’d like to enable that setting.

---

<div class="post-metadata">

### Author: ![Eric\_Hoxworth](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eric_hoxworth/32/41899_2.png) [@Eric\_Hoxworth](https://meta.discourse.org/u/Eric_Hoxworth)
#### Post date: [5월 8, 2015, 10:26오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/5 "2015-05-08T22:26:38Z")

</div>

Seeing this issue too.

The “login required” option might be causing issues in other parts of the program as well - see [Using Discourse API to return user data when the "Require authentication to read content on this site, disallow anonymous access." setting is checked](https://meta.discourse.org/t/using-discourse-api-to-return-user-data-when-the-require-authentication-to-read-content-on-this-site-disallow-anonymous-access-setting-is-checked/28404).

---

<div class="post-metadata">

### Author: ![scott\_sfn](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@scott\_sfn](https://meta.discourse.org/u/scott_sfn)
#### Post date: [7월 8, 2015, 7:46오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/6 "2015-07-08T19:46:48Z")

</div>

We’ve got this issue as well. We’ve got the login required flag on, we’re using the SSO, and when a user’s not logged into Discourse and tries to access a protected thread from a link on our main site, they’re redirected to the root of Discourse when they successfully log in instead of to the thread they want.

We were seeing some strange stuff happening when the login required flag is turned off, but that may be something strange with our implementation as opposed to some general problem, as it’s not consistent.

---

<div class="post-metadata">

### Author: ![scanferla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/scanferla/32/116204_2.png) [@scanferla](https://meta.discourse.org/u/scanferla)
#### Post date: [9월 17, 2015, 2:18오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/7 "2015-09-17T14:18:35Z")

</div>

Hello @sam and @codinghorror,  
We even created a plugin to handle this situation, but it’s not working anymore since our last Discourse upgrade.

So I’m taking this “opportunity” to ask if such plugin is really necessary.

Are there any fixes for this?  
Or, what should I do in order to redirect the user to the proper URL after an SSO login?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [9월 17, 2015, 9:26오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/8 "2015-09-17T21:26:44Z")

</div>

No plugin should be required, this does sound a bit like a bug to me.

I am going to recategorize this PR to fix is welcome.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [9월 17, 2015, 9:29오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/9 "2015-09-17T21:29:27Z")

</div>

This is actually a general bug with login required, we never redirect you back to the original URL.

To repro:

1. enable login required
2. copy url of a topic
3. log out
4. paste url of a topic
5. log in
6. you are on the home page

@techAPJ perhaps add this to your list.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [9월 17, 2015, 9:32오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/10 "2015-09-17T21:32:13Z")

</div>

That used to work, so this is a regression.

confirmed: login now loses the original URL, tested on [parley.rubyrogues.com](http://parley.rubyrogues.com)

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [9월 18, 2015, 1:59오전 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/11 "2015-09-18T01:59:06Z")

</div>

~~Not able to repro this for instances with SSO disabled.~~

Working on a fix for SSO enabled instances.

* * *

UPDATE: seems like I can repro it on SSO disabled instances too, by logging in via Google.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [9월 18, 2015, 1:06오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/12 "2015-09-18T13:06:36Z")

</div>

> [@codinghorror](#):
>
> That used to work, so this is a regression.

> [@techAPJ](#):
>
> I can repro it on SSO disabled instances too, by logging in via Google.

Fixed via:

[https://github.com/discourse/discourse/commit/7abd4687e2d80956d97a006c3a8b2411e1823b72](https://github.com/discourse/discourse/commit/7abd4687e2d80956d97a006c3a8b2411e1823b72)

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [9월 18, 2015, 2:39오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/13 "2015-09-18T14:39:37Z")

</div>

> [@AdamCapriola](#):
>
> users are redirected to root and not originally requested URL

> [@techAPJ](#):
>
> Working on a fix for SSO enabled instances.

I tried to repro this case on my SSO enabled instance and was unable to repro it. Seems like this issue is fixed now. @dansingerman fixed this issue 17 days ago via:

[https://github.com/discourse/discourse/pull/3519](https://github.com/discourse/discourse/pull/3519)

Thanks @dansingerman! 💝

* * *

Can someone else please confirm this fix? cc @scanferla @scott_sfn @Eric_Hoxworth @casey

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [9월 21, 2015, 6:58오후 UTC](https://meta.discourse.org/t/redirect-to-requested-url-after-sso/27820/14 "2015-09-21T18:58:12Z")

</div>

This topic was automatically closed after 3 days. New replies are no longer allowed.
