Browse Source

Replace SmartFormat by C# string interpolation and add Battle.net to the list of supported providers

pull/1732/head
Kévin Chalet 3 years ago
parent
commit
6f8c1ed663
  1. 8
      Directory.Packages.props
  2. 19
      gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
  3. 4
      src/OpenIddict.Client.WebIntegration/OpenIddict.Client.WebIntegration.csproj
  4. 12
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  5. 44
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

8
Directory.Packages.props

@ -45,7 +45,6 @@
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.0.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<PackageVersion Include="System.Collections.Immutable" Version="1.7.1" />
<PackageVersion Include="System.Net.Http.Json" Version="3.2.1" />
<PackageVersion Include="System.Text.Encodings.Web" Version="4.7.2" />
@ -102,7 +101,6 @@
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.0.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<PackageVersion Include="System.Collections.Immutable" Version="1.7.1" />
<PackageVersion Include="System.Net.Http.Json" Version="3.2.1" />
<PackageVersion Include="System.Text.Encodings.Web" Version="4.7.2" />
@ -159,7 +157,6 @@
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.0.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<PackageVersion Include="System.Collections.Immutable" Version="1.7.1" />
<PackageVersion Include="System.Net.Http.Json" Version="3.2.1" />
<PackageVersion Include="System.Text.Encodings.Web" Version="4.7.2" />
@ -241,7 +238,6 @@
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.17763.1000" />
<PackageVersion Include="NamedPipeServerStream.NetFrameworkVersion" Version="1.1.7" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<PackageVersion Include="System.Net.Http.Json" Version="3.2.1" />
<!--
@ -287,7 +283,6 @@
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="6.25.1" />
<PackageVersion Include="MongoDB.Driver" Version="2.18.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<!--
Note: the following references are exclusively used in the test projects:
@ -332,7 +327,6 @@
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="6.25.1" />
<PackageVersion Include="MongoDB.Driver" Version="2.18.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<!--
Note: the following references are exclusively used in the test projects:
@ -400,7 +394,6 @@
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.0.0" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<PackageVersion Include="System.Collections.Immutable" Version="1.7.1" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageVersion Include="System.Net.Http.Json" Version="3.2.1" />
@ -458,7 +451,6 @@
<PackageVersion Include="Microsoft.IdentityModel.Protocols" Version="6.25.1" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="6.25.1" />
<PackageVersion Include="Quartz.Extensions.DependencyInjection" Version="3.5.0" />
<PackageVersion Include="SmartFormat" Version="3.2.0" />
<PackageVersion Include="System.Collections.Immutable" Version="1.7.1" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageVersion Include="System.Net.Http.Json" Version="3.2.1" />

19
gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs

@ -692,8 +692,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Client;
using SmartFormat;
using SmartFormat.Core.Settings;
using static OpenIddict.Client.WebIntegration.OpenIddictClientWebIntegrationConstants;
namespace OpenIddict.Client.WebIntegration;
@ -798,11 +796,6 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
// Resolve the provider options from the service provider and create a registration based on the specified settings.
var settings = _provider.GetRequiredService<IOptionsMonitor<OpenIddictClientWebIntegrationOptions.{{ provider.name }}>>().CurrentValue;
var formatter = Smart.CreateDefaultSmartFormat(new SmartSettings
{
CaseSensitivity = CaseSensitivityType.CaseInsensitive
});
var registration = new OpenIddictClientRegistration
{
ProviderName = Providers.{{ provider.name }},
@ -812,7 +805,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
{
{{~ for environment in provider.environments ~}}
OpenIddictClientWebIntegrationConstants.{{ provider.name }}.Environments.{{ environment.name }}
=> new Uri(formatter.Format(""{{ environment.issuer }}"", settings), UriKind.Absolute),
=> new Uri($""{{ environment.issuer | string.replace '\'' '""' }}"", UriKind.Absolute),
{{~ end ~}}
_ => throw new InvalidOperationException(SR.FormatID0194(nameof(settings.Environment)))
@ -823,7 +816,7 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
{{~ for environment in provider.environments ~}}
OpenIddictClientWebIntegrationConstants.{{ provider.name }}.Environments.{{ environment.name }}
{{~ if environment.configuration_endpoint ~}}
=> new Uri(formatter.Format(""{{ environment.configuration_endpoint }}"", settings), UriKind.Absolute),
=> new Uri($""{{ environment.configuration_endpoint | string.replace '\'' '""' }}"", UriKind.Absolute),
{{~ else ~}}
=> null,
{{~ end ~}}
@ -845,15 +838,15 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
OpenIddictClientWebIntegrationConstants.{{ provider.name }}.Environments.{{ environment.name }} => new OpenIddictConfiguration
{
{{~ if environment.configuration.authorization_endpoint ~}}
AuthorizationEndpoint = new Uri(formatter.Format(""{{ environment.configuration.authorization_endpoint }}"", settings), UriKind.Absolute),
AuthorizationEndpoint = new Uri($""{{ environment.configuration.authorization_endpoint | string.replace '\'' '""' }}"", UriKind.Absolute),
{{~ end ~}}
{{~ if environment.configuration.token_endpoint ~}}
TokenEndpoint = new Uri(formatter.Format(""{{ environment.configuration.token_endpoint }}"", settings), UriKind.Absolute),
TokenEndpoint = new Uri($""{{ environment.configuration.token_endpoint | string.replace '\'' '""' }}"", UriKind.Absolute),
{{~ end ~}}
{{~ if environment.configuration.userinfo_endpoint ~}}
UserinfoEndpoint = new Uri(formatter.Format(""{{ environment.configuration.userinfo_endpoint }}"", settings), UriKind.Absolute),
UserinfoEndpoint = new Uri($""{{ environment.configuration.userinfo_endpoint | string.replace '\'' '""' }}"", UriKind.Absolute),
{{~ end ~}}
CodeChallengeMethodsSupported =
@ -1050,8 +1043,6 @@ public sealed partial class OpenIddictClientWebIntegrationConfiguration
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Client;
using OpenIddict.Client.WebIntegration;
using SmartFormat;
using SmartFormat.Core.Settings;
using static OpenIddict.Client.WebIntegration.OpenIddictClientWebIntegrationConstants;
namespace OpenIddict.Client.WebIntegration;

4
src/OpenIddict.Client.WebIntegration/OpenIddict.Client.WebIntegration.csproj

@ -26,10 +26,6 @@
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SmartFormat" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="**\*.xml" />
</ItemGroup>

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

@ -686,17 +686,13 @@ public static partial class OpenIddictClientWebIntegrationHandlers
//
// The type of account can be defined globally (via the Stripe options) or
// per authentication demand by adding a specific authentication property.
// If the authentication property is present, the global option is ignored.
//
// For more information, see
// https://stripe.com/docs/connect/oauth-reference?locale=en-us#get-authorize.
Providers.StripeConnect when context.Properties.TryGetValue(".stripe_account_type", out string? type) &&
string.Equals(type, "express", StringComparison.OrdinalIgnoreCase)
=> new Uri("https://connect.stripe.com/express/oauth/authorize", UriKind.Absolute),
Providers.StripeConnect when context.Registration.GetStripeConnectOptions() is { AccountType: string type } &&
string.Equals(type, "express", StringComparison.OrdinalIgnoreCase)
=> new Uri("https://connect.stripe.com/express/oauth/authorize", UriKind.Absolute),
Providers.StripeConnect when context.Properties.TryGetValue(".stripe_account_type", out string? type) =>
string.Equals(type, "express", StringComparison.OrdinalIgnoreCase) ?
new Uri("https://connect.stripe.com/express/oauth/authorize", UriKind.Absolute) :
new Uri("https://connect.stripe.com/oauth/authorize", UriKind.Absolute),
_ => context.AuthorizationEndpoint
};

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

@ -20,7 +20,7 @@
doesn't have a generic issuer URI. As such, the complete URI must always be set in the options.
-->
<Environment Issuer="{issuer}" />
<Environment Issuer="{settings.Issuer}" />
<Setting PropertyName="Issuer" ParameterName="issuer" Type="Uri" Required="true"
Description="The URI used to access the ADFS instance, including the virtual directory (e.g https://contoso.com/adfs)" />
@ -86,6 +86,30 @@
<Environment Issuer="https://app.asana.com/api/1.0" />
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ▄▄▀█ ▄▄▀█▄▄ ▄▄█▄▄ ▄▄██ █████ ▄▄▄█████ ▀██ ██ ▄▄▄█▄▄ ▄▄██
██ ▄▄▀█ ▀▀ ███ █████ ████ █████ ▄▄▄█▀▀██ █ █ ██ ▄▄▄███ ████
██ ▀▀ █ ██ ███ █████ ████ ▀▀ ██ ▀▀▀█▄▄██ ██▄ ██ ▀▀▀███ ████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-->
<Provider Name="BattleNet" DisplayName="Battle.net"
Documentation="https://develop.battle.net/documentation/guides/using-oauth">
<!--
Note: most Battle.net regions use the same issuer URI but a different domain is required for China.
-->
<Environment Issuer="https://oauth.{settings.Region switch {
string region when string.Equals(region, 'CN', StringComparison.OrdinalIgnoreCase)
=> 'battlenet.com.cn',
_ => 'battle.net' }}/" />
<Setting PropertyName="Region" ParameterName="region" Type="String" Required="false" DefaultValue="US"
Description="The preferred Battle.net region (by default, 'US')" />
</Provider>
<!--
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
██ ▄▄▀█▄ ▄█▄▄ ▄▄██ ▄▄▀██ ██ ██ ▄▄▀██ █▀▄██ ▄▄▄█▄▄ ▄▄██
@ -115,7 +139,7 @@
<Provider Name="Cognito" DisplayName="Amazon Cognito"
Documentation="https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-reference.html">
<Environment Issuer="https://cognito-idp.{region}.amazonaws.com/{userPoolId}" />
<Environment Issuer="https://cognito-idp.{settings.Region}.amazonaws.com/{settings.UserPoolId}" />
<Setting PropertyName="Region" ParameterName="region" Type="String" Required="true"
Description="The AWS region" />
@ -298,7 +322,7 @@
As such, the complete URI must always be set in the options and include the realm, if applicable.
-->
<Environment Issuer="{issuer}" />
<Environment Issuer="{settings.Issuer}" />
<Setting PropertyName="Issuer" ParameterName="issuer" Type="Uri" Required="true"
Description="The URI used to access the Keycloak identity provider (including the realm, if applicable)" />
@ -369,12 +393,12 @@
Documentation="https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc">
<!--
Note: Microsoft is a multitenant provider that relies on virtual paths to identify instances.
As such, the issuer includes a {tenant} placeholder that will be dynamically replaced
As such, the issuer includes a tenant placeholder that will be dynamically replaced
by OpenIddict at runtime by the tenant configured in the Microsoft Account settings.
If no tenant is explicitly configured, the "common" tenant will be automatically used.
-->
<Environment Issuer="https://login.microsoftonline.com/{tenant}/v2.0" />
<Environment Issuer="https://login.microsoftonline.com/{settings.Tenant}/v2.0" />
<Setting PropertyName="Tenant" ParameterName="tenant" Type="String" Required="false" DefaultValue="common"
Description="The tenant used to identify the Azure AD instance (by default, the common tenant is used)" />
@ -676,11 +700,15 @@
<Provider Name="StripeConnect" DisplayName="Stripe Connect" Documentation="https://stripe.com/docs/connect/oauth-reference">
<Environment Issuer="https://connect.stripe.com/">
<!--
Note: Stripe doesn't provide a userinfo endpoint and returns
the user information via custom token response parameters.
Note: Stripe uses a different authorization endpoint for Express accounts. It also doesn't provide
a userinfo endpoint and returns the user information via custom token response parameters.
-->
<Configuration AuthorizationEndpoint="https://connect.stripe.com/oauth/authorize"
<Configuration AuthorizationEndpoint="{settings.AccountType switch {
string type when string.Equals(type, 'express', StringComparison.OrdinalIgnoreCase)
=> 'https://connect.stripe.com/express/oauth/authorize',
_ => 'https://connect.stripe.com/oauth/authorize' }}"
TokenEndpoint="https://connect.stripe.com/oauth/token" />
<!--

Loading…
Cancel
Save