Skip to main content

User Login with Google OAuth2 for Discourse

Katmandu, Nepal

Configure Discourse to allow login and registration with Google OAuth2.

Creating a new Google Cloud Platform Project

Open the Google Developer Console and Select to Create a new Project:

Using OAuth2 with Discourse

Fill in the Project Name field, then click on Create:

Using OAuth2 with Discourse

Setup OAuth2

Under APIs and Services and select the OAuth consent screen:

Using OAuth2 with Discourse

Select External and then click on Create:

Using OAuth2 with Discourse

Fill out the form then click Save:

Using OAuth2 with Discourse

Go to the Credentials tab on the left, click on + CREATE CREDENTIALS then click on OAuth client ID:

Using OAuth2 with Discourse

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:

Using OAuth2 with Discourse

The OAuth client dialog will appear with client ID and secret:

Using OAuth2 with Discourse

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:

Using OAuth2 with Discourse

Verify your Domain

Using OAuth2 with Discourse

Your site must be registered on Search Console with an https:// URL or with the domain name provider verification method before you can proceed:

Using OAuth2 with Discourse

Add your domain to your Search Console properties:

Using OAuth2 with Discourse

You can now add a HTML Tag to your Discourse page template to verify your ownership over the domain. To do this copy the meta tag Google provides for you:

Using OAuth2 with Discourse

Go to the Discourse Admin and go to the following page: Admin>Customize>Themes, then select Components. Click on Install, then + Create new:

Using OAuth2 with Discourse

Give it a meaningful name (i.e. GoogleSearchConsoleVerification):

Using OAuth2 with Discourse

In your new component, select Edit CSS/HTML, under Custom CSS/HTML. In the </head> section, paste the HTML tag generated by GSC Verification Wizard, then Save this change:

Using OAuth2 with Discourse

Back in the Theme menu add your new component to your default Discourse theme:

Using OAuth2 with Discourse

Back in GSC click on Verify to add your domain to your properties:

Using OAuth2 with Discourse

Back in the OAuth2 configuration you can now add your verified domain without further issues!

Using OAuth2 with Discourse