# Login to Discourse with custom Oauth2 provider

**URL:** https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717
**Category:** Feature
**Tags:** oauth2, completed
**Created:** [April 12, 2014, 12:55pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717 "2014-04-12T12:55:42Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![chzsh1995](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chzsh1995/32/107488_2.png) [@chzsh1995](https://meta.discourse.org/u/chzsh1995)
#### Post date: [April 12, 2014, 12:55pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/1 "2014-04-12T12:55:42Z")

</div>

How do I login to Discourse with my own Oauth2 Provider?

I have an app as a Oauth2 provider, and other apps can use `omniauth-oauth2` or my custom gem to get the info and sign up the user. Can Discourse do so? or admin provides App ID, App Secret and Provider URL then uses these to log in?

---

<div class="post-metadata">

### Author: ![DanielMarquard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielmarquard/32/74010_2.png) [@DanielMarquard](https://meta.discourse.org/u/DanielMarquard)
#### Post date: [April 12, 2014, 2:31pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/2 "2014-04-12T14:31:59Z")

</div>

I also need OAuth. There’s this, the [official single sign-on plugin](https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045) for Discourse, but it won’t suffice for me.

I am developing a first-of-its-kind academic social network for a university and I have my eye on Discourse. I’ll need OAuth to authenticate users against Blackboard, though.

So I’m tossing in my +1 for OAuth. Hopefully it can be supported natively in Discourse. 🙂

---

<div class="post-metadata">

### Author: ![radq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/radq/32/104329_2.png) [@radq](https://meta.discourse.org/u/radq)
#### Post date: [April 12, 2014, 3:34pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/3 "2014-04-12T15:34:28Z")

</div>

Discourse has support for custom [OAuth2 authentication](https://github.com/discourse/discourse/blob/master/lib/auth/oauth2_authenticator.rb) built in, here’s an example of how you can add a custom auth mechanism using OAuth2 via a plugin:

```ruby
require 'auth/oauth2_authenticator'
require 'omniauth-oauth2'

class HummingbirdAuthenticator < ::Auth::OAuth2Authenticator

  CLIENT_ID = '...'
  CLIENT_SECRET = '...'

  def register_middleware(omniauth)
    omniauth.provider :hummingbird, CLIENT_ID, CLIENT_SECRET
  end
end

class OmniAuth::Strategies::Hummingbird < OmniAuth::Strategies::OAuth2
  # Give your strategy a name.
  option :name, "hummingbird"

  # This is where you pass the options you would pass when
  # initializing your consumer from the OAuth gem.
  option :client_options, site: 'http://hummingbird.me'

  # These are called after authentication has succeeded. If
  # possible, you should try to set the UID without making
  # additional calls (if the user id is returned with the token
  # or as a URI parameter). This may not be possible with all
  # providers.
  uid { raw_info['id'].to_s }

  info do
    {
      :name => raw_info['name'],
      :email => raw_info['email']
    }
  end

  extra do
    {
      'raw_info' => raw_info
    }
  end

  def raw_info
    @raw_info ||= access_token.get('/oauth/me.json').parsed
  end
end

auth_provider :title => 'Sign in with Hummingbird account',
    :message => 'Log in using your Hummingbird account. (Make sure your popup blocker is disabled.)',
    :frame_width => 920,
    :frame_height => 800,
    :authenticator => HummingbirdAuthenticator.new('hummingbird', trusted: true,
      auto_create_account: true)

```

---

<div class="post-metadata">

### Author: ![DanielMarquard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielmarquard/32/74010_2.png) [@DanielMarquard](https://meta.discourse.org/u/DanielMarquard)
#### Post date: [April 12, 2014, 8:12pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/4 "2014-04-12T20:12:33Z")

</div>

This is great! Is been searching and didn’t realize there was a solution for this yet. I hope to test it out soon!

---

<div class="post-metadata">

### Author: ![parasquid](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/parasquid/32/4382_2.png) [@parasquid](https://meta.discourse.org/u/parasquid)
#### Post date: [April 14, 2014, 6:17am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/5 "2014-04-14T06:17:24Z")

</div>

I had the same question a month ago, and it was surprisingly easy to create a plugin for login:

[https://github.com/mindvalley/omniauth-mindvalley-discourse](https://github.com/mindvalley/omniauth-mindvalley-discourse)

What took me the longest time to figure out was how to restart the webapp so it can detect the newly installed plugin.

---

<div class="post-metadata">

### Author: ![poliveira89](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/poliveira89/32/122545_2.png) [@poliveira89](https://meta.discourse.org/u/poliveira89)
#### Post date: [January 13, 2015, 10:40am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/6 "2015-01-13T10:40:18Z")

</div>

Your example will work with “OAuth1a” version?

---

<div class="post-metadata">

### Author: ![badevguru](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/badevguru/32/115121_2.png) [@badevguru](https://meta.discourse.org/u/badevguru)
#### Post date: [January 15, 2015, 5:02pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/7 "2015-01-15T17:02:48Z")

</div>

Just wanted to note that the solution does not work for hosted accounts that don’t have access to modify the source at the moment, exposing the Oauth2 configuration through the UI would be a really nice thing!

---

<div class="post-metadata">

### Author: ![Frans\_Thamura](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frans_thamura/32/116704_2.png) [@Frans\_Thamura](https://meta.discourse.org/u/Frans_Thamura)
#### Post date: [September 16, 2015, 3:21am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/9 "2015-09-16T03:21:53Z")

</div>

can i know, how the fb login in discourse work? and which source logic?

we have our own Oauth2 server, [GitHub - meruvian/yama: yama · GitHub](http://www.github.com/meruvian/yama), and real online version is www.merv.id

We want to make discourse as our forum, so we want to change the login using merv.id, or may be using anyone that implement our Yama.

any idea?

---

<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: [September 16, 2015, 3:37am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/10 "2015-09-16T03:37:54Z")

</div>

@eviltrout this request does come up a fair bit, people want to use their existing oauth as sso. Any thoughts on that?

---

<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: [September 16, 2015, 3:46am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/11 "2015-09-16T03:46:35Z")

</div>

we can add “generic oauth settings” but the trouble is that each oauth provider is quirkily a bit different.

It works now fine with plugins.

---

<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: [September 16, 2015, 3:52am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/12 "2015-09-16T03:52:34Z")

</div>

Issue is we do not have plugins on std and biz hosting. So there would need to be a default oauth plugin.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [September 17, 2015, 8:55pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/13 "2015-09-17T20:55:06Z")

</div>

I think we could try and create a default “generic” oauth plugin. Sam is right that each one I’ve done so far is slightly different but we could take a stab at extracting those differences into settings that people could configure.

I would need some example “plain” oauth sites to test out.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [September 24, 2015, 8:49pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/14 "2015-09-24T20:49:13Z")

</div>

I took a stab at this this week and managed to come up with a Basic OAuth2 plugin that works. The caveat is you need to have a JSON endpoint on your server so that we can obtain other information about the user.

[https://github.com/discourse/discourse-oauth2-basic](https://github.com/discourse/discourse-oauth2-basic)

I tested it with [SoundCloud](https://developers.soundcloud.com/) as a provider, and it worked great. I’d love other people to give it a whirl and let me know feedback and I’m sure as we try it out with more providers we’ll find changes and configuration options that will be required.

---

<div class="post-metadata">

### Author: ![beanieboi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/beanieboi/32/122037_2.png) [@beanieboi](https://meta.discourse.org/u/beanieboi)
#### Post date: [February 11, 2016, 8:21pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/15 "2016-02-11T20:21:16Z")

</div>

hey!

thanks for the OAuth2 Provider. it’s working like a charm!  
i have one question, which google couldn’t answer to me.  
is it possible to combine the OAuth2 Plugin with the enable\_sso plugin?

right now when i click the “login with provider” button it connects to our OAuth Provider and grabs all the information and pre-fills the registration form with the user data (like on [meta.discourse.com](http://meta.discourse.com), when i login with GitHub)  
how can i skip the registration and directly create the account? so that the user doesn’t have to register again?

thanks for your help!  
ben

---

<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: [February 11, 2016, 9:35pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/16 "2016-02-11T21:35:52Z")

</div>

No, SSO is mutually exclusive and disables local logins.

---

<div class="post-metadata">

### Author: ![taylorfayle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/taylorfayle/32/63263_2.png) [@taylorfayle](https://meta.discourse.org/u/taylorfayle)
#### Post date: [October 28, 2016, 3:34pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/17 "2016-10-28T15:34:20Z")

</div>

@DanielMarquard Were you successful in getting SSO via Blackboard. I’m thinking Discourse could be a great alternative to BB discussions.

---

<div class="post-metadata">

### Author: ![DanielMarquard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielmarquard/32/74010_2.png) [@DanielMarquard](https://meta.discourse.org/u/DanielMarquard)
#### Post date: [November 1, 2016, 2:27pm UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/18 "2016-11-01T14:27:54Z")

</div>

> [@taylorfayle](#):
>
> @DanielMarquard Were you successful in getting SSO via Blackboard. I’m thinking Discourse could be a great alternative to BB discussions.

I ended up not getting a contract for this project, so I didn’t pursue it further, but I think it could absolutely be done. Have you tried out the [Discourse oAuth 2 plugin](https://github.com/discourse/discourse-oauth2-basic)?

---

<div class="post-metadata">

### Author: ![leog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leog/32/119839_2.png) [@leog](https://meta.discourse.org/u/leog)
#### Post date: [December 22, 2017, 1:42am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/19 "2017-12-22T01:42:48Z")

</div>

> [@codinghorror](#):
>
> No, SSO is mutually exclusive and disables local logins.

Is this still the case? I’ve been trying to close the same gap as @beanieboi described for so long to improve the experience and have a seamless experience for my customers but seems like there is no way around it. Any other suggestion to accomplish this?

Thanks in advance!

---

<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: [December 22, 2017, 1:53am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/20 "2017-12-22T01:53:50Z")

</div>

That is the case, that is the entire _purpose_ of SSO – seamless magic login. Otherwise you want the oAuth 2 menu of providers.

---

<div class="post-metadata">

### Author: ![leog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leog/32/119839_2.png) [@leog](https://meta.discourse.org/u/leog)
#### Post date: [December 22, 2017, 1:56am UTC](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717/21 "2017-12-22T01:56:17Z")

</div>

Here is my problem: [SSO vs Oauth2 difference? - #3 by leog](https://meta.discourse.org/t/sso-vs-oauth2-difference/76543/3)

Seems like I’m confusing things then, or maybe the use case I want to cover isn’t possible.

[Next page](https://meta.discourse.org/t/login-to-discourse-with-custom-oauth2-provider/14717.md?page=2)
