Skip to content

Commit

Permalink
Merge pull request #36781 from romanziske/oidc-provider-discord
Browse files Browse the repository at this point in the history
Added Discord as well-known OIDC provider
  • Loading branch information
sberyozkin authored Oct 31, 2023
2 parents 72e99a3 + 810e49e commit 58bc0c4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
Binary file added docs/src/main/asciidoc/images/oidc-discord-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/main/asciidoc/images/oidc-discord-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/src/main/asciidoc/security-openid-connect-providers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,26 @@ quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.client-secret.value=<Client Secret>
----

[[discord]]
=== Discord

Create a https://discord.com/developers/applications[Discord application]:

image::oidc-discord-1.png[role="thumb"]

You now can get your client id and secret:

image::oidc-discord-2.png[role="thumb"]

You can now configure your `application.properties`:

[source,properties]
----
quarkus.oidc.provider=discord
quarkus.oidc.client-id=<Client ID>
quarkus.oidc.credentials.client-secret=<Client Secret>
----


[[provider-scope]]
== Provider scopes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,7 @@ public static enum ApplicationType {

public static enum Provider {
APPLE,
DISCORD,
FACEBOOK,
GITHUB,
GOOGLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static OidcTenantConfig provider(OidcTenantConfig.Provider provider) {
switch (provider) {
case APPLE:
return apple();
case DISCORD:
return discord();
case FACEBOOK:
return facebook();
case GITHUB:
Expand Down Expand Up @@ -163,4 +165,18 @@ private static OidcTenantConfig twitch() {
ret.getCredentials().getClientSecret().setMethod(Method.POST);
return ret;
}

private static OidcTenantConfig discord() {
// Ref https://discord.com/developers/docs/topics/oauth2
OidcTenantConfig ret = new OidcTenantConfig();
ret.setAuthServerUrl("https://discord.com/api/oauth2");
ret.setDiscoveryEnabled(false);
ret.setAuthorizationPath("authorize");
ret.setTokenPath("token");
ret.getAuthentication().setScopes(List.of("identify", "email"));
ret.getAuthentication().setIdTokenRequired(false);
ret.getToken().setVerifyAccessTokenWithUserInfo(true);
ret.setUserInfoPath("https://discord.com/api/users/@me");
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,41 @@ public void testOverrideTwitchProperties() throws Exception {
assertEquals(Method.BASIC, config.credentials.clientSecret.method.get());
}

@Test
public void testAcceptDiscordProperties() throws Exception {
OidcTenantConfig tenant = new OidcTenantConfig();
tenant.setTenantId(OidcUtils.DEFAULT_TENANT_ID);
OidcTenantConfig config = OidcUtils.mergeTenantConfig(tenant, KnownOidcProviders.provider(Provider.DISCORD));

assertEquals(OidcUtils.DEFAULT_TENANT_ID, config.getTenantId().get());
assertFalse(config.discoveryEnabled.get());
assertEquals("https://discord.com/api/oauth2", config.getAuthServerUrl().get());
assertEquals("authorize", config.getAuthorizationPath().get());
assertEquals("token", config.getTokenPath().get());
assertEquals("https://discord.com/api/users/@me", config.getUserInfoPath().get());
assertEquals(List.of("identify", "email"), config.authentication.scopes.get());
assertFalse(config.getAuthentication().idTokenRequired.get());
}

@Test
public void testOverrideDiscordProperties() throws Exception {
OidcTenantConfig tenant = new OidcTenantConfig();
tenant.setTenantId(OidcUtils.DEFAULT_TENANT_ID);

tenant.setApplicationType(ApplicationType.HYBRID);
tenant.setAuthServerUrl("http://localhost/wiremock");
tenant.credentials.clientSecret.setMethod(Method.BASIC);
tenant.authentication.setForceRedirectHttpsScheme(false);

OidcTenantConfig config = OidcUtils.mergeTenantConfig(tenant, KnownOidcProviders.provider(Provider.DISCORD));

assertEquals(OidcUtils.DEFAULT_TENANT_ID, config.getTenantId().get());
assertEquals(ApplicationType.HYBRID, config.getApplicationType().get());
assertEquals("http://localhost/wiremock", config.getAuthServerUrl().get());
assertFalse(config.getAuthentication().isForceRedirectHttpsScheme().get());
assertEquals(Method.BASIC, config.credentials.clientSecret.method.get());
}

@Test
public void testCorrectTokenType() throws Exception {
OidcTenantConfig.Token tokenClaims = new OidcTenantConfig.Token();
Expand Down

0 comments on commit 58bc0c4

Please sign in to comment.