Browse Source

Update the Discord web provider to support server metadata discovery

Co-Authored-By: Stella  <4118427+StellaAlexis@users.noreply.github.com>
pull/2563/head
Kévin Chalet 2 months ago
parent
commit
ac48051a2b
  1. 35
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs
  2. 12
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  3. 10
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

35
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs

@ -104,8 +104,8 @@ public static partial class OpenIddictClientWebIntegrationHandlers
if (context.Registration.ProviderType is if (context.Registration.ProviderType is
ProviderTypes.AlibabaCloud or ProviderTypes.Apple or ProviderTypes.AlibabaCloud or ProviderTypes.Apple or
ProviderTypes.FaceIt or ProviderTypes.LinkedIn or ProviderTypes.Discord or ProviderTypes.FaceIt or
ProviderTypes.QuickBooksOnline) ProviderTypes.LinkedIn or ProviderTypes.QuickBooksOnline)
{ {
context.Configuration.GrantTypesSupported.Add(GrantTypes.AuthorizationCode); context.Configuration.GrantTypesSupported.Add(GrantTypes.AuthorizationCode);
context.Configuration.GrantTypesSupported.Add(GrantTypes.RefreshToken); context.Configuration.GrantTypesSupported.Add(GrantTypes.RefreshToken);
@ -277,7 +277,8 @@ public static partial class OpenIddictClientWebIntegrationHandlers
// configuration and thus are treated as OAuth 2.0-only providers by the OpenIddict client. // configuration and thus are treated as OAuth 2.0-only providers by the OpenIddict client.
// To avoid that, the "openid" scope is manually added to indicate OpenID Connect is supported. // To avoid that, the "openid" scope is manually added to indicate OpenID Connect is supported.
else if (context.Registration.ProviderType is else if (context.Registration.ProviderType is
ProviderTypes.EpicGames or ProviderTypes.EveOnline or ProviderTypes.Xero) ProviderTypes.Discord or ProviderTypes.EpicGames or
ProviderTypes.EveOnline or ProviderTypes.Xero)
{ {
context.Configuration.ScopesSupported.Add(Scopes.OpenId); context.Configuration.ScopesSupported.Add(Scopes.OpenId);
} }
@ -345,6 +346,23 @@ public static partial class OpenIddictClientWebIntegrationHandlers
ClientAuthenticationMethods.ClientSecretPost); ClientAuthenticationMethods.ClientSecretPost);
} }
// Discord doesn't return the list of supported client authentication methods in its server
// configuration but is known to support both "client_secret_basic" and "client_secret_post".
else if (context.Registration.ProviderType is ProviderTypes.Discord)
{
context.Configuration.TokenEndpointAuthMethodsSupported.Add(
ClientAuthenticationMethods.ClientSecretBasic);
context.Configuration.TokenEndpointAuthMethodsSupported.Add(
ClientAuthenticationMethods.ClientSecretPost);
context.Configuration.RevocationEndpointAuthMethodsSupported.Add(
ClientAuthenticationMethods.ClientSecretBasic);
context.Configuration.RevocationEndpointAuthMethodsSupported.Add(
ClientAuthenticationMethods.ClientSecretPost);
}
// Google doesn't properly implement the device authorization grant, doesn't support // Google doesn't properly implement the device authorization grant, doesn't support
// basic client authentication for the device authorization endpoint and returns // basic client authentication for the device authorization endpoint and returns
// a generic "invalid_request" error when using "client_secret_basic" instead of // a generic "invalid_request" error when using "client_secret_basic" instead of
@ -435,6 +453,17 @@ public static partial class OpenIddictClientWebIntegrationHandlers
context.Registration.Issuer, new Uri("oidc/logout", UriKind.Relative)); context.Registration.Issuer, new Uri("oidc/logout", UriKind.Relative));
} }
// While Discord supports OpenID Connect discovery, the configuration document doesn't include the
// address of the revocation endpoint. To work around that, the endpoint URI is manually added here.
//
// Note: the userinfo endpoint is returned in the configuration document but is replaced here to
// use the same endpoint as the one used in previous OpenIddict versions for compatibility reasons.
else if (context.Registration.ProviderType is ProviderTypes.Discord)
{
context.Configuration.RevocationEndpoint = new Uri("https://discord.com/api/oauth2/token/revoke", UriKind.Absolute);
context.Configuration.UserInfoEndpoint = new Uri("https://discord.com/api/users/@me", UriKind.Absolute);
}
// While Huawei supports OpenID Connect discovery, the configuration // While Huawei supports OpenID Connect discovery, the configuration
// document doesn't return the address of the device authorization endpoint. // document doesn't return the address of the device authorization endpoint.
// To work around that, the endpoint URI is manually added here. // To work around that, the endpoint URI is manually added here.

12
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

@ -917,10 +917,10 @@ public static partial class OpenIddictClientWebIntegrationHandlers
context.DisableBackchannelIdentityTokenNonceValidation = context.Registration.ProviderType switch context.DisableBackchannelIdentityTokenNonceValidation = context.Registration.ProviderType switch
{ {
// These providers don't include the nonce in their identity tokens: // These providers don't include the nonce in their identity tokens:
ProviderTypes.Asana or ProviderTypes.DocuSign or ProviderTypes.Asana or ProviderTypes.Discord or
ProviderTypes.Dropbox or ProviderTypes.FaceIt or ProviderTypes.DocuSign or ProviderTypes.Dropbox or
ProviderTypes.LinkedIn or ProviderTypes.QuickBooksOnline or ProviderTypes.FaceIt or ProviderTypes.LinkedIn or
ProviderTypes.WorldId => true, ProviderTypes.QuickBooksOnline or ProviderTypes.WorldId => true,
_ => context.DisableBackchannelIdentityTokenNonceValidation _ => context.DisableBackchannelIdentityTokenNonceValidation
}; };
@ -1044,6 +1044,10 @@ public static partial class OpenIddictClientWebIntegrationHandlers
context.DisableUserInfoValidation = context.Registration.ProviderType switch context.DisableUserInfoValidation = context.Registration.ProviderType switch
{ {
// The Discord provider uses a custom API endpoint instead of the standard OpenID
// Connect userinfo endpoint for compatibility with previous OpenIddict versions.
ProviderTypes.Discord => true,
// SuperOffice doesn't offer a standard OpenID Connect userinfo endpoint. // SuperOffice doesn't offer a standard OpenID Connect userinfo endpoint.
ProviderTypes.SuperOffice => true, ProviderTypes.SuperOffice => true,

10
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

@ -714,16 +714,6 @@
<Provider Name="Discord" Id="542ac9f1-514f-4b8a-bc4c-d56d2b8356e5" <Provider Name="Discord" Id="542ac9f1-514f-4b8a-bc4c-d56d2b8356e5"
Documentation="https://discord.com/developers/docs/topics/oauth2"> Documentation="https://discord.com/developers/docs/topics/oauth2">
<Environment Issuer="https://discord.com/"> <Environment Issuer="https://discord.com/">
<Configuration AuthorizationEndpoint="https://discord.com/oauth2/authorize"
RevocationEndpoint="https://discord.com/api/oauth2/token/revoke"
TokenEndpoint="https://discord.com/api/oauth2/token"
UserInfoEndpoint="https://discord.com/api/users/@me">
<CodeChallengeMethod Value="S256" />
<GrantType Value="authorization_code" />
<GrantType Value="refresh_token" />
</Configuration>
<!-- <!--
Note: Discord requires sending the "identify" scope to be able to use the userinfo endpoint. Note: Discord requires sending the "identify" scope to be able to use the userinfo endpoint.
--> -->

Loading…
Cancel
Save