How to implement GitHub login in Discourse (quick + clean setup)

If you want to enable “Login with GitHub” for your Discourse forum, here’s the simplest working flow that actually does the job :backhand_index_pointing_down:


:white_check_mark: Step 1: Create a GitHub OAuth App

Go to GitHub Developer Settings:

:backhand_index_pointing_right: Sign in to GitHub · GitHub

  • Create a New OAuth App
  • Set:
    • Homepage URL: https://your-domain.com
    • Authorization callback URL: https://your-domain.com/auth/github/callback
  • Copy the Client ID and Client Secret

:white_check_mark: Step 2: Enable GitHub login in Discourse

In Discourse Admin → Settings → Login :

  • Enable GitHub logins
  • Paste:
    • GitHub Client ID
    • GitHub Client Secret
  • Save changes

:white_check_mark: Step 3: Force HTTPS (important)

Edit your Discourse container config:

vim /var/discourse/containers/app.yml

Under the env: section, add:

DISCOURSE_FORCE_HTTPS: true

This is required if your site is behind HTTPS (Cloudflare, Nginx, etc.), otherwise GitHub OAuth may fail or redirect incorrectly.


:white_check_mark: Step 4: Rebuild Discourse

Apply the changes:

cd /var/discourse
./launcher rebuild app

:tada: Done

After the rebuild:

  • You should see “Log in with GitHub” on the login page
  • OAuth redirect works correctly over HTTPS
  • No more invalid_credentials or redirect issues

Tip:

If you’re using Cloudflare / reverse proxy, make sure:

  • GitHub callback URL uses https

Hope this saves someone a few hours of debugging :raising_hands: