Browse Source

Replace the SUPPORTS_* constants by the built-in target/platform constants

pull/2465/head
Kévin Chalet 5 months ago
parent
commit
8b847421d6
  1. 60
      Directory.Build.targets
  2. 2
      gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs
  3. 34
      shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
  4. 2
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivationHandler.cs
  5. 6
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
  6. 4
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
  7. 6
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs
  8. 31
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs
  9. 31
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs
  10. 6
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
  11. 38
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs
  12. 2
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs
  13. 4
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs
  14. 2
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs
  15. 4
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs
  16. 15
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs
  17. 6
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs
  18. 6
      src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
  19. 2
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs
  20. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs
  21. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs
  22. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs
  23. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs
  24. 2
      src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs
  25. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs
  26. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs
  27. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs
  28. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs
  29. 6
      src/OpenIddict.Server/OpenIddictServerBuilder.cs
  30. 6
      src/OpenIddict.Server/OpenIddictServerConfiguration.cs
  31. 4
      src/OpenIddict.Server/OpenIddictServerHandlers.cs
  32. 2
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs
  33. 4
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs
  34. 15
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs
  35. 6
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs
  36. 2
      test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTests.cs
  37. 2
      test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTests.cs
  38. 6
      test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs

60
Directory.Build.targets

@ -41,66 +41,6 @@
<SupportedOSPlatformVersion Condition=" '$(TargetPlatformIdentifier)' == 'Windows' ">7.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">
<DefineConstants>$(DefineConstants);SUPPORTS_BROTLI_COMPRESSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HEXADECIMAL_STRING_CONVERSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_HTTP_CLIENT_RESILIENCE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_HASHING_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ONE_SHOT_KEY_DERIVATION_METHODS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_PEM_ENCODED_KEY_IMPORT</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_RELAXED_URI_LIMITS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TEXT_ELEMENT_ENUMERATOR</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TIME_CONSTANT_COMPARISONS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_VALUETASK_COMPLETED_TASK</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_X509_CHAIN_POLICY_CLONING</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_X509_CHAIN_POLICY_DOWNLOAD_MODE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_X509_CHAIN_POLICY_TRUST_MODE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_X509_CHAIN_POLICY_VERIFICATION_TIME_MODE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ZLIB_COMPRESSION</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(TargetPlatformIdentifier)' == 'Android' ">
<DefineConstants>$(DefineConstants);SUPPORTS_ANDROID</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ANDROIDX_BROWSER</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And ('$(TargetPlatformIdentifier)' == 'iOS' Or
'$(TargetPlatformIdentifier)' == 'MacCatalyst') ">
<DefineConstants>$(DefineConstants);SUPPORTS_UIKIT</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(TargetPlatformIdentifier)' == 'macOS' ">
<DefineConstants>$(DefineConstants);SUPPORTS_APPKIT</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' And ('$(TargetPlatformIdentifier)' == 'iOS' Or
'$(TargetPlatformIdentifier)' == 'MacCatalyst' Or
'$(TargetPlatformIdentifier)' == 'macOS') ">
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_SERVICES</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_FOUNDATION</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And
'$(TargetPlatformIdentifier)' == 'Windows' And
'$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '8.0'))) Or
('$(TargetFrameworkIdentifier)' == '.NETFramework') ">
<DefineConstants>$(DefineConstants);SUPPORTS_WINDOWS_RUNTIME</DefineConstants>
</PropertyGroup>
<!--
Note: metapackages don't include any build output. To ensure the TFM-specific folders under
/lib are preserved, a placeholder file is added for each supported target framework moniker.

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

@ -448,7 +448,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
return this;
}
#if SUPPORTS_PEM_ENCODED_KEY_IMPORT
#if NET
/// <summary>
/// Configures {{ setting.description }}.
/// </summary>

34
shared/OpenIddict.Extensions/OpenIddictPolyfills.cs

@ -19,8 +19,7 @@ internal static class OpenIddictPolyfills
{
extension(Convert)
{
#if !SUPPORTS_HEXADECIMAL_STRING_CONVERSION
#if !NET
/// <summary>Converts the specified string, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.</summary>
/// <param name="s">The string to convert.</param>
/// <returns>An array of 8-bit unsigned integers that is equivalent to <paramref name="s"/>.</returns>
@ -48,7 +47,7 @@ internal static class OpenIddictPolyfills
extension(HMACSHA256)
{
#if !SUPPORTS_ONE_SHOT_HASHING_METHODS
#if !NET
/// <summary>
/// Computes the HMAC of data using the SHA256 algorithm.
/// </summary>
@ -71,7 +70,7 @@ internal static class OpenIddictPolyfills
extension(OperatingSystem)
{
#if !SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
#if !NET
/// <summary>
/// Indicates whether the current application is running on Android.
/// </summary>
@ -158,8 +157,7 @@ internal static class OpenIddictPolyfills
extension(Rfc2898DeriveBytes)
{
#if !SUPPORTS_ONE_SHOT_KEY_DERIVATION_METHODS
#if !NET
/// <summary>
/// Creates a PBKDF2 derived key from a password.
/// </summary>
@ -200,7 +198,7 @@ internal static class OpenIddictPolyfills
extension(SHA384)
{
#if !SUPPORTS_ONE_SHOT_HASHING_METHODS
#if !NET
/// <summary>
/// Computes the hash of data using the SHA384 algorithm.
/// </summary>
@ -221,7 +219,7 @@ internal static class OpenIddictPolyfills
extension<TResult>(ValueTask<TResult>)
{
#if !SUPPORTS_VALUETASK_COMPLETED_TASK
#if !NET
/// <summary>
/// Gets a task that has already completed successfully.
/// </summary>
@ -229,7 +227,7 @@ internal static class OpenIddictPolyfills
#endif
}
#if !SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
#if !NET
static bool IsOSVersionAtLeast(int major, int minor, int build, int revision)
{
Version current = Environment.OSVersion.Version;
@ -259,23 +257,19 @@ internal static class OpenIddictPolyfills
extension(X509ChainPolicy policy)
{
#if !SUPPORTS_X509_CHAIN_POLICY_CLONING
#if !NET
public X509ChainPolicy Clone()
{
var clone = new X509ChainPolicy
{
#if SUPPORTS_X509_CHAIN_POLICY_DOWNLOAD_MODE
DisableCertificateDownloads = policy.DisableCertificateDownloads,
#endif
RevocationMode = policy.RevocationMode,
RevocationFlag = policy.RevocationFlag,
#if SUPPORTS_X509_CHAIN_POLICY_TRUST_MODE
TrustMode = policy.TrustMode,
#endif
UrlRetrievalTimeout = policy.UrlRetrievalTimeout,
VerificationFlags = policy.VerificationFlags,
VerificationTime = policy.VerificationTime,
#if SUPPORTS_X509_CHAIN_POLICY_VERIFICATION_TIME_MODE
#if NET
DisableCertificateDownloads = policy.DisableCertificateDownloads,
TrustMode = policy.TrustMode,
VerificationTimeIgnored = policy.VerificationTimeIgnored
#endif
};
@ -296,7 +290,7 @@ internal static class OpenIddictPolyfills
}
}
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
clone.CustomTrustStore.AddRange(policy.CustomTrustStore);
#endif
@ -316,7 +310,7 @@ internal static class OpenIddictPolyfills_SHA512
{
extension(SHA512)
{
#if !SUPPORTS_ONE_SHOT_HASHING_METHODS
#if !NET
/// <summary>
/// Computes the hash of data using the SHA512 algorithm.
/// </summary>
@ -336,7 +330,7 @@ internal static class OpenIddictPolyfills_SHA512
}
}
#if !SUPPORTS_TIME_CONSTANT_COMPARISONS
#if !NET
internal static class CryptographicOperations
{
/// <summary>

2
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationActivationHandler.cs

@ -71,7 +71,7 @@ public sealed class OpenIddictClientSystemIntegrationActivationHandler : IHosted
[MethodImpl(MethodImplOptions.NoInlining)]
static OpenIddictClientSystemIntegrationActivation? GetProtocolActivation()
{
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
// On platforms that support WinRT, always favor the AppInstance.GetActivatedEventArgs() API.
if (IsAppInstanceActivationSupported() && GetProtocolActivationUriWithWindowsRuntime() is Uri uri)
{

6
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs

@ -70,7 +70,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#if !SUPPORTS_ANDROID
#if !ANDROID
// When running on Android, iOS or Mac Catalyst, ensure the version compiled for these platforms
// is used to prevent the generic/non-OS specific TFM from being used as launching the system
// browser cannot be done using Process.Start() and requires using OS-specific APIs that are
@ -81,7 +81,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
}
#endif
#if !SUPPORTS_UIKIT
#if !IOS && !MACCATALYST
if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
@ -162,7 +162,7 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
options.ApplicationDiscriminator;
}
#if SUPPORTS_CURRENT_USER_ONLY_PIPE_OPTION
#if NET
if (options.PipeOptions is null && !OperatingSystem.IsWindows())
{
// Note: the CurrentUserOnly option is also supported on Windows, but is less

4
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs

@ -35,7 +35,7 @@ public static class OpenIddictClientSystemIntegrationExtensions
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#if !SUPPORTS_ANDROID
#if !ANDROID
// When running on Android, iOS or Mac Catalyst, ensure the version compiled for these platforms
// is used to prevent the generic/non-OS specific TFM from being used as launching the system
// browser cannot be done using Process.Start() and requires using OS-specific APIs that are
@ -46,7 +46,7 @@ public static class OpenIddictClientSystemIntegrationExtensions
}
#endif
#if !SUPPORTS_UIKIT
#if !IOS && !MACCATALYST
if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));

6
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs

@ -32,7 +32,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES
#if IOS || MACCATALYST || MACOS
if (IsASWebAuthenticationSessionSupported())
{
if (!context.Transaction.Properties.TryGetValue(
@ -79,7 +79,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
#if ANDROID
if (IsCustomTabsIntentSupported())
{
if (!context.Transaction.Properties.TryGetValue(
@ -215,7 +215,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
if (IsWebAuthenticationBrokerSupported())
{
if (!context.Transaction.Properties.TryGetValue(

31
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs

@ -9,27 +9,24 @@ using System.Runtime.Versioning;
using System.Text;
using Microsoft.Extensions.Primitives;
#if SUPPORTS_ANDROID
#if ANDROID
using Android.Content;
using NativeUri = Android.Net.Uri;
#endif
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
using AndroidX.Browser.CustomTabs;
using NativeUri = Android.Net.Uri;
#endif
#if SUPPORTS_AUTHENTICATION_SERVICES
#if IOS || MACCATALYST || MACOS
using AuthenticationServices;
using Microsoft.Extensions.Logging;
#endif
#if SUPPORTS_APPKIT
#if MACOS
using NativeWindow = AppKit.NSWindow;
#elif SUPPORTS_UIKIT
#elif IOS || MACCATALYST
using NativeWindow = UIKit.UIWindow;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
using Windows.Security.Authentication.Web;
using Windows.UI.Core;
#endif
@ -100,7 +97,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
#if IOS || MACCATALYST || MACOS
if (string.IsNullOrEmpty(context.RedirectUri) ||
!Uri.TryCreate(context.RedirectUri, UriKind.Absolute, out Uri? uri))
{
@ -284,7 +281,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
#endif
}
#if SUPPORTS_AUTHENTICATION_SERVICES
#if IOS || MACCATALYST || MACOS
class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject,
IASWebAuthenticationPresentationContextProviding
{
@ -320,7 +317,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
#if ANDROID
if (string.IsNullOrEmpty(context.RedirectUri))
{
return;
@ -393,7 +390,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
if (string.IsNullOrEmpty(context.RedirectUri))
{
return;
@ -562,7 +559,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
// To avoid that, the OpenIddict host needs to determine whether the platform supports Windows
// Runtime APIs and favor the Launcher.LaunchUriAsync() API when it's offered by the platform.
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
if (IsUriLauncherSupported() && await TryLaunchBrowserWithWindowsRuntimeAsync(uri))
{
context.HandleRequest();
@ -578,21 +575,21 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
// On Android, iOS and Mac Catalyst, Process.Start() is not supported and
// OS-specific/non-portable APIs must be used to launch the system browser.
#if SUPPORTS_ANDROID
#if ANDROID
if (OperatingSystem.IsAndroid() && TryLaunchBrowserWithGenericIntent(uri))
{
context.HandleRequest();
return;
}
#endif
#if SUPPORTS_UIKIT
#if IOS || MACCATALYST
if ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) && await TryLaunchBrowserWithUIApplicationAsync(uri))
{
context.HandleRequest();
return;
}
#endif
#if SUPPORTS_APPKIT
#if MACOS
if (OperatingSystem.IsMacOS() && TryLaunchBrowserWithNSWorkspace(uri))
{
context.HandleRequest();

31
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs

@ -9,27 +9,24 @@ using System.Runtime.Versioning;
using System.Text;
using Microsoft.Extensions.Primitives;
#if SUPPORTS_ANDROID
#if ANDROID
using Android.Content;
using NativeUri = Android.Net.Uri;
#endif
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
using AndroidX.Browser.CustomTabs;
using NativeUri = Android.Net.Uri;
#endif
#if SUPPORTS_AUTHENTICATION_SERVICES
#if IOS || MACCATALYST || MACOS
using AuthenticationServices;
using Microsoft.Extensions.Logging;
#endif
#if SUPPORTS_APPKIT
#if MACOS
using NativeWindow = AppKit.NSWindow;
#elif SUPPORTS_UIKIT
#elif IOS || MACCATALYST
using NativeWindow = UIKit.UIWindow;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
using Windows.Security.Authentication.Web;
using Windows.UI.Core;
#endif
@ -100,7 +97,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
#if IOS || MACCATALYST || MACOS
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri) ||
!Uri.TryCreate(context.PostLogoutRedirectUri, UriKind.Absolute, out Uri? uri))
{
@ -284,7 +281,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
#endif
}
#if SUPPORTS_AUTHENTICATION_SERVICES
#if IOS || MACCATALYST || MACOS
class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject,
IASWebAuthenticationPresentationContextProviding
{
@ -320,7 +317,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
#if ANDROID
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
{
return;
@ -393,7 +390,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
{
return;
@ -562,7 +559,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
// To avoid that, the OpenIddict host needs to determine whether the platform supports Windows
// Runtime APIs and favor the Launcher.LaunchUriAsync() API when it's offered by the platform.
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
if (IsUriLauncherSupported() && await TryLaunchBrowserWithWindowsRuntimeAsync(uri))
{
context.HandleRequest();
@ -578,21 +575,21 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
// On Android, iOS and Mac Catalyst, Process.Start() is not supported and
// OS-specific/non-portable APIs must be used to launch the system browser.
#if SUPPORTS_ANDROID
#if ANDROID
if (OperatingSystem.IsAndroid() && TryLaunchBrowserWithGenericIntent(uri))
{
context.HandleRequest();
return;
}
#endif
#if SUPPORTS_UIKIT
#if IOS || MACCATALYST
if ((OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) && await TryLaunchBrowserWithUIApplicationAsync(uri))
{
context.HandleRequest();
return;
}
#endif
#if SUPPORTS_APPKIT
#if MACOS
if (OperatingSystem.IsMacOS() && TryLaunchBrowserWithNSWorkspace(uri))
{
context.HandleRequest();

6
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs

@ -1827,7 +1827,6 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
SupportedServerResponseModes: context.Configuration.ResponseModesSupported) switch
{
#if SUPPORTS_WINDOWS_RUNTIME
// When using the web authentication broker on Windows, if both the client and
// the server support response_mode=fragment, use it if the response types contain
// a value that prevents response_mode=query from being used (token/id_token).
@ -1848,7 +1847,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
client.Contains(ResponseModes.Fragment) &&
(types.Contains(ResponseTypes.IdToken) || types.Contains(ResponseTypes.Token))
=> ResponseModes.Fragment,
#endif
// When using browser-based authentication with a redirect_uri not pointing to the embedded server,
// if both the client and the server support response_mode=fragment, use it if the response types
// contain a value that prevents response_mode=query from being used (token/id_token).
@ -1901,7 +1900,6 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
({ Count: > 0 } client, { Count: 0 }) when client.Contains(ResponseModes.Query)
=> ResponseModes.Query,
#if SUPPORTS_WINDOWS_RUNTIME
// When using the web authentication broker on Windows, if both
// the client and the server support response_mode=fragment, use it.
({ Count: > 0 } client, { Count: > 0 } server) when
@ -1909,7 +1907,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
IsAuthenticationMode(OpenIddictClientSystemIntegrationAuthenticationMode.WebAuthenticationBroker) &&
client.Contains(ResponseModes.Fragment) && server.Contains(ResponseModes.Fragment)
=> ResponseModes.Fragment,
#endif
// When using browser-based authentication with a redirect_uri not pointing to the embedded
// server, if both the client and the server support response_mode=fragment, use it.
({ Count: > 0 } client, { Count: > 0 } server) when

38
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs

@ -13,23 +13,19 @@ using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Principal;
#if SUPPORTS_ANDROID
#if ANDROID
using Android.Content;
using NativeUri = Android.Net.Uri;
#endif
#if SUPPORTS_FOUNDATION
using Foundation;
#endif
#if SUPPORTS_APPKIT
#if MACOS
using AppKit;
using NativeWindow = AppKit.NSWindow;
#elif SUPPORTS_UIKIT
#elif IOS || MACCATALYST
using NativeWindow = UIKit.UIWindow;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel;
using Windows.Foundation.Metadata;
@ -77,7 +73,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[SupportedOSPlatformGuard("maccatalyst13.1")]
[SupportedOSPlatformGuard("macos10.15")]
internal static bool IsASWebAuthenticationSessionSupported()
#if SUPPORTS_AUTHENTICATION_SERVICES
#if IOS || MACCATALYST || MACOS
=> OperatingSystem.IsIOSVersionAtLeast(12) ||
OperatingSystem.IsMacCatalystVersionAtLeast(13) ||
OperatingSystem.IsMacOSVersionAtLeast(10, 15);
@ -92,7 +88,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SupportedOSPlatformGuard("android21.0")]
internal static bool IsCustomTabsIntentSupported()
#if SUPPORTS_ANDROIDX_BROWSER
#if ANDROID
=> OperatingSystem.IsAndroidVersionAtLeast(21);
#else
=> false;
@ -111,7 +107,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
// platforms that don't support it. Since OpenIddict declares Windows 10 1809 as the
// oldest supported version in the package, it is also used for the runtime check.
internal static bool IsWindowsRuntimeSupported()
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
=> OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17763);
#else
=> false;
@ -126,7 +122,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[SupportedOSPlatformGuard("windows10.0.17763")]
internal static bool IsAppInstanceActivationSupported()
{
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
return IsWindowsRuntimeSupported() && IsApiPresent();
[MethodImpl(MethodImplOptions.NoInlining)]
@ -148,7 +144,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[SupportedOSPlatformGuard("windows10.0.17763")]
internal static bool IsUriLauncherSupported()
{
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
return IsWindowsRuntimeSupported() && IsApiPresent();
[MethodImpl(MethodImplOptions.NoInlining)]
@ -170,7 +166,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
[SupportedOSPlatformGuard("windows10.0.17763")]
internal static bool IsWebAuthenticationBrokerSupported()
{
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
return IsWindowsRuntimeSupported() && IsApiPresent();
[MethodImpl(MethodImplOptions.NoInlining)]
@ -221,16 +217,16 @@ public static class OpenIddictClientSystemIntegrationHelpers
out uint ReturnLength);
}
#if SUPPORTS_APPKIT || SUPPORTS_UIKIT
#if IOS || MACCATALYST || MACOS
/// <summary>
/// Gets a reference to the current <see cref="NativeWindow"/>.
/// </summary>
/// <returns>The <see cref="NativeWindow"/> or <see langword="null"/> if it couldn't be resolved.</returns>
internal static NativeWindow? GetCurrentUIWindow()
{
#if SUPPORTS_APPKIT
#if MACOS
return NSApplication.SharedApplication.KeyWindow;
#elif SUPPORTS_UIKIT
#else
var window = GetKeyWindow();
if (window is not null && window.WindowLevel == UIWindowLevel.Normal)
{
@ -292,7 +288,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
}
#endif
#if SUPPORTS_WINDOWS_RUNTIME
#if NETFRAMEWORK || WINDOWS10_0_17763_0_OR_GREATER
/// <summary>
/// Resolves the protocol activation using the Windows Runtime APIs, if applicable.
/// </summary>
@ -393,7 +389,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
}
}
#if SUPPORTS_ANDROID
#if ANDROID
/// <summary>
/// Starts the system browser using <see href="NSWorkspace"/>.
/// </summary>
@ -420,7 +416,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
}
#endif
#if SUPPORTS_APPKIT
#if MACOS
/// <summary>
/// Starts the system browser using <see href="NSWorkspace"/>.
/// </summary>
@ -441,7 +437,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
}
#endif
#if SUPPORTS_UIKIT
#if IOS || MACCATALYST
/// <summary>
/// Starts the system browser using <see href="UIApplication"/>.
/// </summary>

2
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationPipeListener.cs

@ -131,7 +131,7 @@ public sealed class OpenIddictClientSystemIntegrationPipeListener : BackgroundSe
// Note: the ACL-based PipeSecurity class is only supported on Windows. On other operating systems,
// PipeOptions.CurrentUserOnly can be used as an alternative, but only for TFMs that implement it.
=> OperatingSystem.IsWindows() ?
#if SUPPORTS_NAMED_PIPE_STATIC_FACTORY_WITH_ACL
#if NET
NamedPipeServerStreamAcl.Create(
#else
new NamedPipeServerStream(

4
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs

@ -11,7 +11,7 @@ using System.Security.Principal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
#if SUPPORTS_ANDROID
#if ANDROID
using Android.Content;
using OpenIddict.Extensions;
#endif
@ -42,7 +42,7 @@ public sealed class OpenIddictClientSystemIntegrationService
_provider = provider ?? throw new ArgumentNullException(nameof(provider));
}
#if SUPPORTS_ANDROID && SUPPORTS_ANDROIDX_BROWSER
#if ANDROID
/// <summary>
/// Handles the specified intent.
/// </summary>

2
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs

@ -204,7 +204,7 @@ public sealed class OpenIddictClientSystemNetHttpBuilder
return Configure(options => options.HttpErrorPolicy = policy);
}
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
/// <summary>
/// Replaces the default HTTP resilience pipeline used by the OpenIddict client services.
/// </summary>

4
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpConfiguration.cs

@ -13,7 +13,7 @@ using Microsoft.Extensions.Http;
using Microsoft.Extensions.Options;
using Polly;
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
using Microsoft.Extensions.Http.Resilience;
#endif
@ -110,7 +110,7 @@ public sealed class OpenIddictClientSystemNetHttpConfiguration : IConfigureOptio
builder.AdditionalHandlers.Add(new PolicyHttpMessageHandler(policy));
}
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
else if (options.CurrentValue.HttpResiliencePipeline is ResiliencePipeline<HttpResponseMessage> pipeline)
{
#pragma warning disable EXTEXP0001

15
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpHandlers.cs

@ -312,7 +312,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION || SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY
#if NET
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
var request = context.Transaction.GetHttpRequestMessage() ??
@ -321,15 +321,9 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
var client = context.Transaction.GetHttpClient() ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0372));
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION
// If supported, import the HTTP version from the client instance.
// When supported, import the HTTP version and version policy from the client instance.
request.Version = client.DefaultRequestVersion;
#endif
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY
// If supported, import the HTTP version policy from the client instance.
request.VersionPolicy = client.DefaultVersionPolicy;
#endif
#endif
return ValueTask.CompletedTask;
}
@ -753,7 +747,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
stream = new GZipStream(stream, CompressionMode.Decompress);
}
#if SUPPORTS_ZLIB_COMPRESSION
#if NET
// Note: some server implementations are known to incorrectly implement the "Deflate" compression
// algorithm and don't wrap the compressed data in a ZLib frame as required by the specifications.
//
@ -766,8 +760,7 @@ public static partial class OpenIddictClientSystemNetHttpHandlers
stream ??= await response.Content.ReadAsStreamAsync();
stream = new ZLibStream(stream, CompressionMode.Decompress);
}
#endif
#if SUPPORTS_BROTLI_COMPRESSION
else if (string.Equals(encoding, ContentEncodings.Brotli, StringComparison.OrdinalIgnoreCase))
{
stream ??= await response.Content.ReadAsStreamAsync();

6
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpOptions.cs

@ -13,7 +13,7 @@ using System.Security.Cryptography.X509Certificates;
using Polly;
using Polly.Extensions.Http;
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
using Microsoft.Extensions.Http.Resilience;
#endif
@ -31,13 +31,13 @@ public sealed class OpenIddictClientSystemNetHttpOptions
/// Note: on .NET 8.0 and higher, this property is set to <see langword="null"/> by default.
/// </remarks>
public IAsyncPolicy<HttpResponseMessage>? HttpErrorPolicy { get; set; }
#if !SUPPORTS_HTTP_CLIENT_RESILIENCE
#if !NET
= HttpPolicyExtensions.HandleTransientHttpError()
.OrResult(static response => response.StatusCode is HttpStatusCode.NotFound)
.WaitAndRetryAsync(4, static attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)));
#endif
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
/// <summary>
/// Gets or sets the HTTP resilience pipeline used by the internal OpenIddict HTTP clients.
/// </summary>

6
src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs

@ -831,7 +831,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
OpenIddictHelpers.IsClientAuthenticationCertificate(certificate) &&
OpenIddictHelpers.IsSelfIssuedCertificate(certificate))
{
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
policy.CustomTrustStore.Add(certificate);
#else
policy.ExtraStore.Add(certificate);
@ -1479,7 +1479,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
// Note: using a policy relying on the default system trust store
// is strongly discouraged but deliberately not prevented here.
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
var uris = await GetRedirectUrisAsync(application, cancellationToken);
if (uris.IsDefaultOrEmpty)
{
@ -1646,7 +1646,7 @@ public class OpenIddictApplicationManager<TApplication> : IOpenIddictApplication
// Note: using a policy relying on the default system trust store
// is strongly discouraged but deliberately not prevented here.
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
using var chain = new X509Chain()
{
ChainPolicy = policy

2
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs

@ -73,7 +73,7 @@ public sealed class OpenIddictEntityFrameworkBuilder
throw new InvalidOperationException(SR.GetResourceString(SR.ID0277));
}
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
// If the specified key type isn't a string (which is special-cased by the stores to avoid having to resolve
// a TypeDescriptor instance) and the platform supports type registration, register the key type to ensure the
// TypeDescriptor associated with that type will be preserved by the IL Linker and can be resolved at runtime.

4
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkApplicationStore.cs

@ -1066,7 +1066,7 @@ public class OpenIddictEntityFrameworkApplicationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -1097,7 +1097,7 @@ public class OpenIddictEntityFrameworkApplicationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

4
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs

@ -905,7 +905,7 @@ public class OpenIddictEntityFrameworkAuthorizationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -936,7 +936,7 @@ public class OpenIddictEntityFrameworkAuthorizationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

4
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs

@ -695,7 +695,7 @@ public class OpenIddictEntityFrameworkScopeStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -726,7 +726,7 @@ public class OpenIddictEntityFrameworkScopeStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

4
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs

@ -1039,7 +1039,7 @@ public class OpenIddictEntityFrameworkTokenStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -1070,7 +1070,7 @@ public class OpenIddictEntityFrameworkTokenStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

2
src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreBuilder.cs

@ -86,7 +86,7 @@ public sealed class OpenIddictEntityFrameworkCoreBuilder
where TToken : OpenIddictEntityFrameworkCoreToken<TKey, TApplication, TAuthorization>
where TKey : notnull, IEquatable<TKey>
{
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
// If the specified key type isn't a string (which is special-cased by the stores to avoid having to resolve
// a TypeDescriptor instance) and the platform supports type registration, register the key type to ensure the
// TypeDescriptor associated with that type will be preserved by the IL Linker and can be resolved at runtime.

4
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs

@ -1145,7 +1145,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -1176,7 +1176,7 @@ public class OpenIddictEntityFrameworkCoreApplicationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

4
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs

@ -1085,7 +1085,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -1116,7 +1116,7 @@ public class OpenIddictEntityFrameworkCoreAuthorizationStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

4
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs

@ -709,7 +709,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -740,7 +740,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

4
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs

@ -1198,7 +1198,7 @@ public class OpenIddictEntityFrameworkCoreTokenStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));
@ -1229,7 +1229,7 @@ public class OpenIddictEntityFrameworkCoreTokenStore<
else
{
var converter =
#if SUPPORTS_TYPE_DESCRIPTOR_TYPE_REGISTRATION
#if NET
TypeDescriptor.GetConverterFromRegisteredType(typeof(TKey));
#else
TypeDescriptor.GetConverter(typeof(TKey));

6
src/OpenIddict.Server/OpenIddictServerBuilder.cs

@ -1791,7 +1791,7 @@ public sealed class OpenIddictServerBuilder
foreach (var character in charset)
{
#if SUPPORTS_TEXT_ELEMENT_ENUMERATOR
#if NET
// On supported platforms, ensure each character added to the
// charset represents exactly one grapheme cluster/text element.
var enumerator = StringInfo.GetTextElementEnumerator(character);
@ -2269,7 +2269,7 @@ public sealed class OpenIddictServerBuilder
ArgumentNullException.ThrowIfNull(certificates);
ArgumentNullException.ThrowIfNull(configuration);
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
// Ensure at least one root certificate authority was included in the certificate collection.
if (!certificates.Cast<X509Certificate2>().Any(static certificate =>
OpenIddictHelpers.IsCertificateAuthority(certificate) &&
@ -2379,7 +2379,7 @@ public sealed class OpenIddictServerBuilder
{
ArgumentNullException.ThrowIfNull(configuration);
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
var policy = new X509ChainPolicy
{
// Note: by default, OpenIddict requires that end certificates used for TLS client

6
src/OpenIddict.Server/OpenIddictServerConfiguration.cs

@ -328,7 +328,7 @@ public sealed class OpenIddictServerConfiguration : IPostConfigureOptions<OpenId
throw new InvalidOperationException(SR.GetResourceString(SR.ID0511));
}
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE && SUPPORTS_X509_CHAIN_POLICY_TRUST_MODE
#if NET
if (options.PublicKeyInfrastructureTlsClientAuthenticationPolicy.CustomTrustStore.Cast<X509Certificate2>()
.Any(static certificate =>
!OpenIddictHelpers.IsCertificateAuthority(certificate) ||
@ -353,7 +353,7 @@ public sealed class OpenIddictServerConfiguration : IPostConfigureOptions<OpenId
throw new InvalidOperationException(SR.GetResourceString(SR.ID0502));
}
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE && SUPPORTS_X509_CHAIN_POLICY_TRUST_MODE
#if NET
if (options.SelfSignedTlsClientAuthenticationPolicy.CustomTrustStore.Count is not 0)
{
throw new InvalidOperationException(SR.GetResourceString(SR.ID0502));
@ -489,7 +489,7 @@ public sealed class OpenIddictServerConfiguration : IPostConfigureOptions<OpenId
foreach (var character in options.UserCodeCharset)
{
#if SUPPORTS_TEXT_ELEMENT_ENUMERATOR
#if NET
// On supported platforms, ensure each character added to the
// charset represents exactly one grapheme cluster/text element.
var enumerator = StringInfo.GetTextElementEnumerator(character);

4
src/OpenIddict.Server/OpenIddictServerHandlers.cs

@ -1318,7 +1318,7 @@ public static partial class OpenIddictServerHandlers
// Note: to allow validating certificates that are exclusively used for mTLS token binding, the chain policy
// is amended to consider the specified self-signed certificate as a trusted root and basically disable chain
// validation while still validating the other aspects of the certificate (e.g expiration date, key usage, etc).
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
policy.CustomTrustStore.Add(context.Transaction.RemoteCertificate);
#else
policy.ExtraStore.Add(context.Transaction.RemoteCertificate);
@ -1441,7 +1441,7 @@ public static partial class OpenIddictServerHandlers
// Always clone the X.509 chain policy to ensure the original instance is never mutated.
policy = policy.Clone();
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
policy.CustomTrustStore.Add(context.Transaction.RemoteCertificate);
#else
policy.ExtraStore.Add(context.Transaction.RemoteCertificate);

2
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs

@ -112,7 +112,7 @@ public sealed class OpenIddictValidationSystemNetHttpBuilder
return Configure(options => options.HttpErrorPolicy = policy);
}
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
/// <summary>
/// Replaces the default HTTP resilience pipeline used by the OpenIddict client services.
/// </summary>

4
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpConfiguration.cs

@ -13,7 +13,7 @@ using Microsoft.Extensions.Http;
using Microsoft.Extensions.Options;
using Polly;
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
using Microsoft.Extensions.Http.Resilience;
#endif
@ -107,7 +107,7 @@ public sealed class OpenIddictValidationSystemNetHttpConfiguration : IConfigureO
builder.AdditionalHandlers.Add(new PolicyHttpMessageHandler(policy));
}
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
else if (options.CurrentValue.HttpResiliencePipeline is ResiliencePipeline<HttpResponseMessage> pipeline)
{
#pragma warning disable EXTEXP0001

15
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpHandlers.cs

@ -195,7 +195,7 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers
{
ArgumentNullException.ThrowIfNull(context);
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION || SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY
#if NET
// This handler only applies to System.Net.Http requests. If the HTTP request cannot be resolved,
// this may indicate that the request was incorrectly processed by another client stack.
var request = context.Transaction.GetHttpRequestMessage() ??
@ -204,15 +204,9 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers
var client = context.Transaction.GetHttpClient() ??
throw new InvalidOperationException(SR.GetResourceString(SR.ID0372));
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION
// If supported, import the HTTP version from the client instance.
// When supported, import the HTTP version and version policy from the client instance.
request.Version = client.DefaultRequestVersion;
#endif
#if SUPPORTS_HTTP_CLIENT_DEFAULT_REQUEST_VERSION_POLICY
// If supported, import the HTTP version policy from the client instance.
request.VersionPolicy = client.DefaultVersionPolicy;
#endif
#endif
return ValueTask.CompletedTask;
}
@ -638,7 +632,7 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers
stream = new GZipStream(stream, CompressionMode.Decompress);
}
#if SUPPORTS_ZLIB_COMPRESSION
#if NET
// Note: some server implementations are known to incorrectly implement the "Deflate" compression
// algorithm and don't wrap the compressed data in a ZLib frame as required by the specifications.
//
@ -651,8 +645,7 @@ public static partial class OpenIddictValidationSystemNetHttpHandlers
stream ??= await response.Content.ReadAsStreamAsync();
stream = new ZLibStream(stream, CompressionMode.Decompress);
}
#endif
#if SUPPORTS_BROTLI_COMPRESSION
else if (string.Equals(encoding, ContentEncodings.Brotli, StringComparison.OrdinalIgnoreCase))
{
stream ??= await response.Content.ReadAsStreamAsync();

6
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpOptions.cs

@ -13,7 +13,7 @@ using System.Security.Cryptography.X509Certificates;
using Polly;
using Polly.Extensions.Http;
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
using Microsoft.Extensions.Http.Resilience;
#endif
@ -31,13 +31,13 @@ public sealed class OpenIddictValidationSystemNetHttpOptions
/// Note: on .NET 8.0 and higher, this property is set to <see langword="null"/> by default.
/// </remarks>
public IAsyncPolicy<HttpResponseMessage>? HttpErrorPolicy { get; set; }
#if !SUPPORTS_HTTP_CLIENT_RESILIENCE
#if !NET
= HttpPolicyExtensions.HandleTransientHttpError()
.OrResult(static response => response.StatusCode is HttpStatusCode.NotFound)
.WaitAndRetryAsync(4, static attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)));
#endif
#if SUPPORTS_HTTP_CLIENT_RESILIENCE
#if NET
/// <summary>
/// Gets or sets the HTTP resilience pipeline used by the internal OpenIddict HTTP clients.
/// </summary>

2
test/OpenIddict.Server.AspNetCore.IntegrationTests/OpenIddictServerAspNetCoreIntegrationTests.cs

@ -72,7 +72,7 @@ public partial class OpenIddictServerAspNetCoreIntegrationTests : OpenIddictServ
await client.GetAsync("/.well-known/openid-configuration", new OpenIddictRequest());
}
#if !SUPPORTS_RELAXED_URI_LIMITS
#if !NET
[Fact]
public async Task ProcessRequest_IgnoresInvalidRequestUris()
{

2
test/OpenIddict.Server.IntegrationTests/OpenIddictServerIntegrationTests.cs

@ -1099,7 +1099,7 @@ public abstract partial class OpenIddictServerIntegrationTests
Mock.Get(manager).Verify(manager => manager.ValidateClientSecretAsync(application, "7Fjfp0ZBr1KtDRbnfVdmIw", It.IsAny<CancellationToken>()), Times.Once());
}
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
[Theory]
[InlineData(OpenIddictServerEndpointType.Introspection)]
[InlineData(OpenIddictServerEndpointType.Revocation)]

6
test/OpenIddict.Server.Tests/OpenIddictServerBuilderTests.cs

@ -768,7 +768,7 @@ public class OpenIddictServerBuilderTests
Assert.Equal("certificates", exception.ParamName);
}
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
[Fact]
public void EnablePublicKeyInfrastructureTlsClientAuthentication_ThrowsAnExceptionWhenNoRootCertificateProvided()
{
@ -1123,7 +1123,7 @@ public class OpenIddictServerBuilderTests
Assert.Equal("configuration", exception.ParamName);
}
#if SUPPORTS_X509_CHAIN_POLICY_CUSTOM_TRUST_STORE
#if NET
[Fact]
public void EnableSelfSignedTlsClientAuthentication_PolicyIsCorrectlyConfigured()
{
@ -2683,7 +2683,7 @@ public class OpenIddictServerBuilderTests
Assert.Equal("charset", exception.ParamName);
}
#if SUPPORTS_TEXT_ELEMENT_ENUMERATOR
#if NET
[InlineData("")]
[InlineData("\uD83D\uDE42\uD83D\uDE42")]
[Theory]

Loading…
Cancel
Save