Oauth2 with GitHub howto

For all those people having issues to get oauth2 to work with GitHub, here’s a solution.

Problem: Discourse oauth2 plugin generates a 500 error when enabled with Github and the fields in configuration are not correctly set. As documentation is spare about what and how to configure, here are the important (and some optional) fields:

OAuth2 client ID Client ID from GitHub
OAuth2 client secret Client Secret from GitHub
OAuth2 authorize URL https[:]//github[.]com/login/oauth/authorize
OAuth2 token URL https[:]//github[.]com/login/oauth/access_token
OAuth2 token URL method POST
OAuth2 user JSON URL https[:]//api.github[.]com/user
OAuth2 user JSON URL method GET
OAuth2 JSON user ID path id
OAuth2 JSON username path login
OAuth2 JSON name path name
OAuth2 JSON email path mail
OAuth2 JSON avatar path avatar_url
OAuth2 send auth header x
OAuth2 send auth body x
OAuth2 allow association change x

for debugging (only):
OAuth2 debug auth x

On GitHub side, in case you’re missing this information as well, here’s what is needed:
Go to https[:]//github[.]com/settings/developers, click on “New OAuth App”
Enter Application Name (e.g. Discourse),
Homepage URL
and
Authorization callback URL (https[:]//YOUR.DISCOURSESERV[.]ER/auth/oauth2_basic/callback)
and don’t forget to click on Update application.

That’s it.
Hope that helps!

Can I ask the developers to please check the (invalid because empty) return when the mandatory “OAuth2 user JSON URL” is not set? It generates this error and throws a 500.

ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR: null value in column “provider_uid” of relation “user_associated_accounts” violates not-null constraint

Sorry for the obfuscation in the URLs, I have been told that new users can only have 2 links per post.