Add an OpenID Connect with Discord IdP

On this page

Add a Login with Discord button to the FusionAuth login pages. FusionAuth connects to Discord through the OpenID Connect Identity Provider. After you configure the Identity Provider, you can enable the button for one or more Applications.

The following login page shows the Discord button:

A FusionAuth login page with a button to log in with Discord.
A FusionAuth login page with a button to log in with Discord.

The following diagram shows a login through Discord on the FusionAuth hosted login pages:

Identity ProviderFusionAuthYour ApplicationUser/BrowserIdentity ProviderFusionAuthYour ApplicationUser/BrowserClick LoginRedirect to the FusionAuth login pageClick the Identity Provider buttonRedirect to the Identity ProviderLog inRedirect to FusionAuth with the login resultFollow the redirect to the FusionAuth callback URLRequest the user's tokens or profileReturn the tokens or profileReconcile, link, and create the user and registration as neededRedirect to your application with an authorization codeFollow the redirectExchange the authorization code for tokensReturn FusionAuth tokens
Identity ProviderFusionAuthYour ApplicationUser/BrowserIdentity ProviderFusionAuthYour ApplicationUser/BrowserClick LoginRedirect to the FusionAuth login pageClick the Identity Provider buttonRedirect to the Identity ProviderLog inRedirect to FusionAuth with the login resultFollow the redirect to the FusionAuth callback URLRequest the user's tokens or profileReturn the tokens or profileReconcile, link, and create the user and registration as neededRedirect to your application with an authorization codeFollow the redirectExchange the authorization code for tokensReturn FusionAuth tokens

A user logs in through an Identity Provider on the FusionAuth hosted login pages.

The user sees only the FusionAuth login page, the login page of Discord, and your application. Your application completes a standard OAuth authorization code grant with FusionAuth, and FusionAuth handles the exchange with Discord.

For more information about Discord OAuth, see Discord OAuth2.

Register a Discord OAuth2 Application#

  1. Log in to the Discord Developer Portal, and create an application.

  2. In the left navigation, open Selected App -> Settings -> OAuth2 .

    The Discord OAuth2 settings for an application, with the client Id, the client secret, and a redirect URL.
    The Discord OAuth2 settings for an application, with the client Id, the client secret, and a redirect URL.
  3. Add the redirect URLThe URL where the authorization server sends the browser after login, with an authorization code or an error. of FusionAuth, which is the FusionAuth URL followed by /oauth2/callback. For FusionAuth at https://login.piedpiper.com, the redirect URL is https://login.piedpiper.com/oauth2/callback.

  4. Copy the CLIENT ID and the CLIENT SECRET. The FusionAuth Identity Provider needs both values.

Configure the OpenID Connect Identity Provider#

  1. In the Admin UI, navigate to Settings -> Identity Providers , and add an OpenID Connect Identity Provider. For the full add steps, see Add an OpenID Connect IdP.

  2. Set Client Id and Client secret to the CLIENT ID and CLIENT SECRET values from Discord.

  3. Set Button text to Login with Discord.

  4. Turn off Discover endpoints. Discord documents the user fields of the /users/@me endpoint, not the userinfo endpoint in the Discord discovery document. Enter the following endpoints:

    • Authorization endpoint: https://discord.com/oauth2/authorize
    • Token endpoint: https://discord.com/api/v10/oauth2/token
    • Userinfo endpoint: https://discord.com/api/v10/users/@me
  5. Set Scope to identify email.

  6. Set Client authentication to Request body (client_secret_post). Discord also accepts HTTP basic authentication (client_secret_basic).

  7. On the Options tab, set Unique Id claim to id and Email verified claim to verified. Discord doesn't use the standard claim names. Without verified, FusionAuth links on Discord email addresses that Discord hasn't verified. For more information, see Options.

    The Options tab of an OpenID Connect Identity Provider for Discord, with the Discord claim names.
    The Options tab of an OpenID Connect Identity Provider for Discord, with the Discord claim names.
  8. On the Applications tab, turn on Enabled for each Application that offers Discord login. To register new users for an Application, turn on Create registration.

  9. Click .

The login page of each enabled Application then shows the Login with Discord button.

The following image shows the top of a Discord Identity Provider configuration:

The top of the form for an OpenID Connect Identity Provider configured for Discord.
The top of the form for an OpenID Connect Identity Provider configured for Discord.

The following image shows the Applications tab, with the Identity Provider enabled for the PiperChat Application and Create registration turned on:

The Applications tab of the Discord Identity Provider, enabled for the PiperChat Application with Create registration turned on.
The Applications tab of the Discord Identity Provider, enabled for the PiperChat Application with Create registration turned on.

Add Discord Profile Data#

The Discord implementation of OpenID Connect doesn't follow the full specification. To add more profile data to the user, such as the Discord username and the avatar URL, set a Reconcile lambda on the Identity Provider. For more information, see the OpenID Connect reconcile lambda.