Browse Source

Introduce runtime checks preventing the non-platform-specific version of OpenIddict.Client.SystemIntegration from being used on iOS/macOS/Mac Catalyst

pull/2120/head
Kévin Chalet 2 years ago
parent
commit
d200d86ef2
  1. 3
      src/OpenIddict.Abstractions/OpenIddictResources.resx
  2. 9
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
  3. 9
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs

3
src/OpenIddict.Abstractions/OpenIddictResources.resx

@ -1680,6 +1680,9 @@ To apply post-logout redirection responses, create a class implementing 'IOpenId
<data name="ID0448" xml:space="preserve">
<value>An unknown error occurred while trying to start an AS web authentication session.</value>
</data>
<data name="ID0449" xml:space="preserve">
<value>The generic version of the OpenIddict.Client.SystemIntegration package cannot be used on this platform. Make sure your application is referencing the correct version by using the appropriate OS-specific TFM (e.g on macOS, 'net8.0-macos10.15').</value>
</data>
<data name="ID2000" xml:space="preserve">
<value>The security token is missing.</value>
</data>

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

@ -83,6 +83,15 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#if !SUPPORTS_APPKIT && !SUPPORTS_UIKIT
// When running on iOS, Mac Catalyst or macOS, ensure the version compiled for these platforms is used.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) ||
RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) ||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
#pragma warning disable CA1416
// If explicitly set, ensure the specified authentication mode is supported.
if (options.AuthenticationMode is OpenIddictClientSystemIntegrationAuthenticationMode.ASWebAuthenticationSession &&

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

@ -40,6 +40,15 @@ public static class OpenIddictClientSystemIntegrationExtensions
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));
}
#if !SUPPORTS_APPKIT && !SUPPORTS_UIKIT
// When running on iOS, Mac Catalyst or macOS, ensure the version compiled for these platforms is used.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) ||
RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) ||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0449));
}
#endif
// Note: the OpenIddict activation handler service is deliberately registered as early as possible to
// ensure protocol activations can be handled before another service can stop the initialization of the
// application (e.g Dapplo.Microsoft.Extensions.Hosting.AppServices relies on an IHostedService to implement

Loading…
Cancel
Save