# Create a DiscourseConnect login link

**URL:** https://meta.discourse.org/t/create-a-discourseconnect-login-link/109290
**Category:** Integrations
**Tags:** sso, discourseconnect, how-to
**Created:** [February 15, 2019, 11:00pm UTC](https://meta.discourse.org/t/create-a-discourseconnect-login-link/109290 "2019-02-15T23:00:14Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [July 18, 2024, 12:54pm UTC](https://meta.discourse.org/t/create-a-discourseconnect-login-link/109290/5 "2024-07-18T12:54:55Z")

</div>

I think what is happening is that when you visit a route like `https://forum.example.com/session/sso?return_path=/t/some-slug/23`, Discourse redirects you to the `discourse connect url`, regardless of whether you are logged into Discourse or not. That happens here:

> <https://github.com/discourse/discourse/blob/main/app/controllers/session_controller.rb#L25-L42>

The SSO provider site is then expected to handle the case of users who are already logged into the site. Here’s how the [WP Discourse](https://github.com/discourse/wp-discourse) plugin handles it:

> <https://github.com/discourse/wp-discourse/blob/main/lib/sso-provider/discourse-sso.php#L148-L171>

That code (what follows the `else` statement) handles the case of users who are already logged into WordPress. They are redirected back to the URL that’s supplied by the `return_path` query param. So from the user’s point of view, they are taken directly to the return path URL, but what actually happens is that they are redirected to the SSO provider site, then back to Discourse.

I _think_ the problem on your site is that your SSO code isn’t handling the case of users who are already logged into the site.

I don’t have things setup to test this right now. It’s possible that I’m reading the code incorrectly. Before looking at the code, I thought that a check was run on the Discourse end to see if the user was already logged into Discourse, but that does not seem to be the way it works.

---

_[View the full topic](https://meta.discourse.org/t/create-a-discourseconnect-login-link/109290)._
