# SSO redirection using Microsoft Oauth2 plugin(without login button)

**URL:** https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004
**Category:** SSO
**Created:** [December 24, 2018, 12:14pm UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004 "2018-12-24T12:14:43Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Subham\_Joshi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/subham_joshi/32/127591_2.png) [@Subham\_Joshi](https://meta.discourse.org/u/Subham_Joshi)
#### Post date: [December 24, 2018, 12:14pm UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004/1 "2018-12-24T12:14:43Z")

</div>

I need to login into discourse without clicking “Log In” button, currently I had implemented Microsoft Oauth2 authentication.  
I checked the settings “enable sso” it used “/session/sso” for login & redirect.  
Can there be any way like “/session/sso” for login(without click) using Oauth 2.

---

<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: [December 25, 2018, 7:05am UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004/2 "2018-12-25T07:05:53Z")

</div>

> [@Subham\_Joshi](#):
>
> Can there be any way like “/session/sso” for login(without click) using Oauth 2.

Yes… we can do something here… to clarify. You want a special path:

`https://mydiscourse.com/auth/oauth2` and when you link to that from anywhere user is going to end up being logged in? (we may already have this working just need to confirm that it works for both logged in and not, also how the redirect after login works)

Stuff is a bit slow at the moment but we will get back to you on this in the next week or so.

@david can you add to your list?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 26, 2018, 1:26pm UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004/3 "2018-12-26T13:26:36Z")

</div>

> [@Subham\_Joshi](#):
>
> Can there be any way like “/session/sso” for login(without click) using Oauth 2

If you have only one authentication method configured on your discourse instance, just use

```plaintext
https://mydiscourse.com/login

```

As @sam mentioned, you can also use the specific `/auth` URLs for all non-sso login methods. For the oauth2-basic plugin, the url is:

```plaintext
https://mydiscourse.com/auth/oauth2_basic

```

For the discourse-azure-ad plugin, the URL is

```plaintext
https://mydiscourse.com/auth/azure_oauth2

```

The behaviour for all of these methods is slightly different depending on whether the user is already logged in/registered to discourse:

- Not logged in, not registered

- Not logged in, registered

- Already logged in to another account, registered

- Already logged in to another account, not registered

---

<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: [December 26, 2018, 2:37pm UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004/4 "2018-12-26T14:37:33Z")

</div>

Just to expand on this, how do we handle “login redirect”, eg: if the originator wants the user not to end up on the home page?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 26, 2018, 3:04pm UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004/5 "2018-12-26T15:04:23Z")

</div>

In core this is all handled automagically by the login button, but if you did want to send a user somewhere special after login you can add the `?origin=` parameter to the `/auth` URL

For example: [http://try.discourse.org/auth/facebook?origin=/t/60](http://try.discourse.org/auth/facebook?origin=/t/60)

---

<div class="post-metadata">

### Author: ![adopilot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adopilot/32/105040_2.png) [@adopilot](https://meta.discourse.org/u/adopilot)
#### Post date: [December 26, 2018, 9:15pm UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004/6 "2018-12-26T21:15:54Z")

</div>

We have private site, and no need ever to login if user is already login on site providing SSO

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/8/58993ab6c022099688147dee34da030e4cd79e33.png)

---

<div class="post-metadata">

### Author: ![Subham\_Joshi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/subham_joshi/32/127591_2.png) [@Subham\_Joshi](https://meta.discourse.org/u/Subham_Joshi)
#### Post date: [December 27, 2018, 6:20am UTC](https://meta.discourse.org/t/sso-redirection-using-microsoft-oauth2-plugin-without-login-button/105004/7 "2018-12-27T06:20:29Z")

</div>

Hey,

Thanks a lot guys for your help, we got it working just need to change some settings.

Check these 2 settings as true -  
**login required** - Require authentication to read content on this site, disallow anonymous access.  
**enable sso** - Enable single sign on via an external site.  
Add sso\_url as “[sso\_url](https://your-domain/auth/azure_oauth2)” and sso secret(your app secret).

And for logout go to User Settings & add a “logout redirect” as [microsoft logout](https://login.microsoftonline.com/common/oauth2/logout) or parent url.  
Using these settings whenever we hit the discourse domain url it checks for the parent sso login.
