From fea943370c614c26bd7152761415dde16ec7518b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Tue, 27 Jun 2023 19:28:33 +0200 Subject: [PATCH] Add Salesforce to the list of supported providers --- ...tClientWebIntegrationHandlers.Discovery.cs | 15 ++++++-- ...penIddictClientWebIntegrationProviders.xml | 31 +++++++++++------ .../OpenIddictClientHandlers.cs | 34 +++++++++---------- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs index cf776d49..e873c82d 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.Discovery.cs @@ -106,13 +106,16 @@ public static partial class OpenIddictClientWebIntegrationHandlers // authorization code or implicit flows). To work around that, the list of supported grant // types is amended to include the known supported types for the providers that require it. - if (context.Registration.ProviderType is ProviderTypes.Apple or ProviderTypes.LinkedIn or ProviderTypes.QuickBooksOnline) + if (context.Registration.ProviderType is + ProviderTypes.Apple or ProviderTypes.LinkedIn or ProviderTypes.QuickBooksOnline) { context.Configuration.GrantTypesSupported.Add(GrantTypes.AuthorizationCode); context.Configuration.GrantTypesSupported.Add(GrantTypes.RefreshToken); } - else if (context.Registration.ProviderType is ProviderTypes.Cognito or ProviderTypes.EpicGames or ProviderTypes.Microsoft) + else if (context.Registration.ProviderType is + ProviderTypes.Cognito or ProviderTypes.EpicGames or + ProviderTypes.Microsoft or ProviderTypes.Salesforce) { context.Configuration.GrantTypesSupported.Add(GrantTypes.AuthorizationCode); context.Configuration.GrantTypesSupported.Add(GrantTypes.ClientCredentials); @@ -162,12 +165,18 @@ public static partial class OpenIddictClientWebIntegrationHandlers // always uses Proof Key for Code Exchange for these providers, the supported methods // are manually added to the list of supported code challenge methods by this handler. - if (context.Registration.ProviderType is ProviderTypes.Adobe or ProviderTypes.Autodesk or ProviderTypes.Microsoft) + if (context.Registration.ProviderType is + ProviderTypes.Adobe or ProviderTypes.Autodesk or ProviderTypes.Microsoft) { context.Configuration.CodeChallengeMethodsSupported.Add(CodeChallengeMethods.Plain); context.Configuration.CodeChallengeMethodsSupported.Add(CodeChallengeMethods.Sha256); } + else if (context.Registration.ProviderType is ProviderTypes.Salesforce) + { + context.Configuration.CodeChallengeMethodsSupported.Add(CodeChallengeMethods.Sha256); + } + return default; } } diff --git a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml index 9296ff73..1bc0d25f 100644 --- a/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml +++ b/src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml @@ -214,8 +214,7 @@ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ --> - + - + - + + + + + + + + + - + - + null, + { + // If the list of code challenge methods supported by the + // client is empty, don't use Proof Key for Code Exchange. + ({ Count: 0 }, { Count: _ }) => null, - // If the server doesn't specify a list of code challenge methods, - // Proof Key for Code Exchange is assumed to be unsupported. - ({ Count: > 0 }, { Count: 0 }) => null, + // If the server doesn't specify a list of code challenge methods, + // Proof Key for Code Exchange is assumed to be unsupported. + ({ Count: > 0 }, { Count: 0 }) => null, - // If both the client and the server support S256, use it. - ({ Count: > 0 } client, { Count: > 0 } server) when - client.Contains(CodeChallengeMethods.Sha256) && server.Contains(CodeChallengeMethods.Sha256) - => CodeChallengeMethods.Sha256, + // If both the client and the server support S256, use it. + ({ Count: > 0 } client, { Count: > 0 } server) when + client.Contains(CodeChallengeMethods.Sha256) && server.Contains(CodeChallengeMethods.Sha256) + => CodeChallengeMethods.Sha256, - // If both the client and the server support plain, use it. - ({ Count: > 0 } client, { Count: > 0 } server) when - client.Contains(CodeChallengeMethods.Plain) && server.Contains(CodeChallengeMethods.Plain) - => CodeChallengeMethods.Plain, + // If both the client and the server support plain, use it. + ({ Count: > 0 } client, { Count: > 0 } server) when + client.Contains(CodeChallengeMethods.Plain) && server.Contains(CodeChallengeMethods.Plain) + => CodeChallengeMethods.Plain, - _ => null - }; + _ => null + }; // Note: while enforced by OAuth 2.1 under certain circumstances, PKCE is not a required feature for // OAuth 2.0 and OpenID Connect (where features like nonce validation can serve similar purposes).