Configuring Google login for Discourse


(Neil Lalonde) #1

Here’s how to configure Discourse to allow login and registration with Google OAuth2.

  1. Go to https://console.developers.google.com, on the top left click on Select a project
    image

  2. On the top right, click on New Project

  3. Fill in the project fields. You can also edit the Project ID (optional), then click on Create
    (This can take a while, so wait a minute as needed for it to appear.)

    3a. It is possible that errors are displayed after creating the project. Ignore them and refresh the page with Ctrl+F5

  4. Select your project clicking on the project name

  5. Open the dropdown menu clicking on Create credentials and choose OAuth client ID .

  6. Configure your OAuth Consent Screen.


    6a.Fill as appropriate; we recommend populating all these fields, then click Save.
    In the example below we use https://demo-site.com, be sure to use the URL of your Discourse site including http:// or https:// .

  7. Choose “Web application” as the Application Type.
    In the Authorized JavaScript Origins section, add your site’s base url, including http:// or https://.
    In the Authorized Redirect URI section, add the base url with /auth/google_oauth2/callback. Click the Create button.

  8. The OAuth client dialog will appear with client ID and secret.
    image

  9. Click Library in the left menu
    image

  10. Scroll down the page until you’ll see a huge list of Google API’s. Find Google+ API and click on it:
    image

    and in the new window click on the Enable button

  11. In your Discourse site settings, check “enable google oauth2 logins”, and fill in your google oauth2 client id and google auth2 client secret provided earlier.

That’s it, Google login should now work on your Discourse! Go ahead and test it out with any Google account.


Configure oauth callback urls
Google and linkedin Login/Signin stoped working
Configure oauth callback urls
Oauth Login requests 'offline access'
How to setup google oAuth2 on site?
User should be able to login without verification
Sso with google account
Mysterious Google Cloud project
[Paid] Discourse configuration changes
(Chuck Kalish) #157

I think I got Google in order, but I might now be misconfigured in Discourse. After clicking “with Google” I get this error in a Discourse window:

Sorry, there was an error authorizing your account. Perhaps you did not approve authorization?

Is that on the google authenticating side, or on the discourse side?

Thanks.


(Stephen) #158

Usually this means one or more APIs weren’t enabled AFAIK?

Check which project they were configured against. That still catches me out occasionally.


(jdorfman) #159

I’m having the same issue as @Chuck_Kalish. Any help would be appreciated.


(Stephen) #160

Which APIs have you enabled against the project you set up for Google login to your site?


(jdorfman) #161

We have GitHub and Twitter OAuth working if that is what you mean.


(Stephen) #162

No, I mean when you configured Google authentication one of the steps was to create a project and enable specific APIs at the developer console. Which APIs did you enable?


(jdorfman) #163

Does this help?

Sorry I’m a noob =p


(Stephen) #164

Go back to the Dashboard and look at the bottom - that’s where specific APIs are listed. Both Contacts API and Google+ API should be listed:

45%20PM


(jdorfman) #165

it works. Thanks @Stephen!


(Stephen) #166

Excellent, glad to hear it.


(Neil Lalonde) #167

I’m curious about this solution. Our instructions currently only say you need Google+ API. Should we add the Contacts API too?


(Joshua Rosenfeld) #168

Shouldn’t need it. Both @Dax and I tested this last month and only enabled the Google+ API. Looking at the edit history we removed Contacts API from the instructions in Dec 2017.


(Stephen) #169

Cool, looks like it was just Google+ he was missing then (hope that gets renamed soon) - @jdorfman can you confirm what you added yesterday?


(jdorfman) #170

I added both even though I thought Google+ was shutting down soon.


(Stephen) #171

Google+ the social network will go away, yes, but that login API will be sticking around for the foreseeable future, although maybe with a different name.