Configuring Discord Login for Discourse

The latest version of Discourse supports authentication via Discord. Combining Discourse and Discord is a great way to combine the real-time features of chat with the ‘long term memory’ of a Discourse forum. You can read more about this on our blog.

Once enabled and configured, login with Discord will appear alongside the other login methods for your forum:

Configuration

To get started, head over to Discord developer portal and create a new application. Choose a name, icon and description of your choice. These will be shown to users during the login flow.

Copy the Client ID and Client Secret from this screen, and enter them into your Discourse settings under discord_client_id and discord_client_secret.

Next, visit the OAuth2 tab on the left. Under Redirects, enter your Discourse site URL (including https://), followed by /auth/discord/callback. Make sure you hit Save Changes before closing the window. Don’t worry about using the ‘OAuth2 URL Generator’ - Discourse will handle that automatically.

Finally, go back to your Discourse site and enable the enable_discord_logins site setting. You should now have a working Discord login button on your site :tada:

Restricting access by Guild

By default, any Discord user can log into your Discourse forum. To restrict access to specific guilds, you can use the discord_trusted_guilds site setting.

First of all, find out the numeric ID for your Discord guild. The easiest way is to login to your guild and open a random channel. Check the URL in your browser, and copy the first number you see in it. The URL format is https://discordapp.com/channels/{guild}/{channel}. For example, given a URL as https://discordapp.com/channels/123/456, your guild ID would be 123.

Once you have the guild ID, add it to the discord_trusted_guilds setting in your Discourse site settings. You can add as many guilds to this list as you like. Now, users in the trusted guilds will be logged straight into your site. Anyone else will be shown this message when they try and get in. You can modify the message from your admin panel by searching for discord.not_in_allowed_guild under CustomizeText.

If you are relying on this guild restriction for security, make sure to disable all other Discourse login methods.

What next?

Now that your users can login with Discord, how about setting up the chat-integration plugin as well? That will push important topics from Discourse straight into your Discord channels. For more information, check out the chat-integration setup information.

10 Likes