Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Discord as well-known OIDC provider #36781

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading