Browse Source

Update OpenIddict.Client.SystemIntegration to target Mac Catalyst 13.1+ and macOS 10.15+

pull/2117/head
Kévin Chalet 2 years ago
parent
commit
b6bce3e5dd
  1. 35
      Directory.Build.props
  2. 54
      Directory.Build.targets
  3. 2
      sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml.cs
  4. 2
      sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml.cs
  5. 2
      sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml.cs
  6. 2
      sandbox/OpenIddict.Sandbox.Maui.Client/MauiHostApplicationLifetime.cs
  7. 2
      sandbox/OpenIddict.Sandbox.Maui.Client/MauiHostedServiceAdapter.cs
  8. 2
      sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs
  9. 1
      sandbox/OpenIddict.Sandbox.Maui.Client/OpenIddict.Sandbox.Maui.Client.csproj
  10. 11
      sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/AppDelegate.cs
  11. 14
      sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/Entitlements.plist
  12. 38
      sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/Info.plist
  13. 11
      sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/Program.cs
  14. 4
      sandbox/OpenIddict.Sandbox.Maui.Client/Program.cs
  15. 2
      sandbox/OpenIddict.Sandbox.Maui.Client/Worker.cs
  16. 6
      src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj
  17. 2
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationAuthenticationMode.cs
  18. 2
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationBuilder.cs
  19. 6
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationConfiguration.cs
  20. 6
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
  21. 2
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlerFilters.cs
  22. 29
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Authentication.cs
  23. 29
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.Session.cs
  24. 8
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHandlers.cs
  25. 84
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationHelpers.cs
  26. 8
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationService.cs
  27. 2
      src/OpenIddict/OpenIddict.csproj

35
Directory.Build.props

@ -43,6 +43,31 @@
('$(GITHUB_ACTIONS)' == 'true' Or ('$(DotNetRoot)' != '' And Exists('$(DotNetRoot)packs\Microsoft.iOS.Ref')) Or
('$(DOTNET_HOST_PATH)' != '' And Exists('$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))\packs\Microsoft.iOS.Ref')) Or
('$(MSBuildRuntimeType)' != 'Core' And Exists('$(ProgramFiles)\dotnet\packs\Microsoft.iOS.Ref'))) ">true</SupportsIOSPlatformTargeting>
<!--
Note: targeting Mac Catalyst requires installing the .NET Mac Catalyst workload. To ensure the solution
can be built on machines that don't have the Mac Catalyst workload installed, a directory check is used to
ensure the Mac Catalyst reference assemblies pack is present on the machine before targeting Mac Catalyst.
-->
<SupportsMacCatalystPlatformTargeting
Condition=" '$(SupportsMacCatalystPlatformTargeting)' == '' And $([System.OperatingSystem]::IsWindows()) And
('$(GITHUB_ACTIONS)' == 'true' Or ('$(DotNetRoot)' != '' And Exists('$(DotNetRoot)packs\Microsoft.MacCatalyst.Ref')) Or
('$(DOTNET_HOST_PATH)' != '' And Exists('$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))\packs\Microsoft.MacCatalyst.Ref')) Or
('$(MSBuildRuntimeType)' != 'Core' And Exists('$(ProgramFiles)\dotnet\packs\Microsoft.MacCatalyst.Ref'))) ">true</SupportsMacCatalystPlatformTargeting>
<!--
Note: targeting macOS requires installing the .NET macOS workload. To ensure the solution can be
built on machines that don't have the macOS workload installed, a directory check is used to
ensure the macOS reference assemblies pack is present on the machine before targeting macOS.
-->
<SupportsMacOSPlatformTargeting
Condition=" '$(SupportsMacOSPlatformTargeting)' == '' And $([System.OperatingSystem]::IsWindows()) And
('$(GITHUB_ACTIONS)' == 'true' Or ('$(DotNetRoot)' != '' And Exists('$(DotNetRoot)packs\Microsoft.macOS.Ref')) Or
('$(DOTNET_HOST_PATH)' != '' And Exists('$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))\packs\Microsoft.macOS.Ref')) Or
('$(MSBuildRuntimeType)' != 'Core' And Exists('$(ProgramFiles)\dotnet\packs\Microsoft.macOS.Ref'))) ">true</SupportsMacOSPlatformTargeting>
<!--
Note: while <EnableWindowsTargeting>true</EnableWindowsTargeting> can be used to allow targeting Windows,
Windows targets are only used when running on Windows to speed up the build on non-Windows platforms.
-->
<SupportsWindowsPlatformTargeting
Condition=" '$(SupportsWindowsPlatformTargeting)' == '' And $([System.OperatingSystem]::IsWindows()) ">true</SupportsWindowsPlatformTargeting>
@ -76,6 +101,16 @@
net8.0-ios13.0
</NetCoreIOSTargetFrameworks>
<NetCoreMacCatalystTargetFrameworks
Condition=" '$(NetCoreMacCatalystTargetFrameworks)' == '' And '$(SupportsMacCatalystPlatformTargeting)' == 'true' ">
net8.0-maccatalyst13.1
</NetCoreMacCatalystTargetFrameworks>
<NetCoreMacOSTargetFrameworks
Condition=" '$(NetCoreMacOSTargetFrameworks)' == '' And '$(SupportsMacOSPlatformTargeting)' == 'true' ">
net8.0-macos10.15
</NetCoreMacOSTargetFrameworks>
<NetCoreWindowsTargetFrameworks
Condition=" '$(NetCoreWindowsTargetFrameworks)' == '' And '$(SupportsWindowsPlatformTargeting)' == 'true' ">
net6.0-windows7.0;

54
Directory.Build.targets

@ -22,6 +22,20 @@
<SupportedOSPlatformVersion>12.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'MacCatalyst' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '13.1'))) ">
<SupportedOSPlatformVersion>13.1</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'macOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '10.15'))) ">
<SupportedOSPlatformVersion>10.15</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'Windows' And '$(TargetPlatformVersion)' != '' And
@ -146,15 +160,49 @@
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'iOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '12.0'))) ">
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_SERVICES</DefineConstants>
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '12.0'))) Or
('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'MacCatalyst' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '13.1'))) ">
<DefineConstants>$(DefineConstants);SUPPORTS_UIKIT</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'macOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '10.15'))) ">
<DefineConstants>$(DefineConstants);SUPPORTS_APPKIT</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'iOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '13.0'))) ">
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '12.0'))) Or
('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'MacCatalyst' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '13.1'))) Or
('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'macOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '10.15'))) ">
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHENTICATION_SERVICES</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_FOUNDATION</DefineConstants>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'iOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '13.0'))) Or
('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'MacCatalyst' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '13.1'))) Or
('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'macOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '10.15'))) ">
<DefineConstants>$(DefineConstants);SUPPORTS_PRESENTATION_CONTEXT_PROVIDER</DefineConstants>
</PropertyGroup>

2
sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml.cs

@ -1,4 +1,4 @@
#if IOS || WINDOWS
#if IOS || MACCATALYST || WINDOWS
namespace OpenIddict.Sandbox.Maui.Client;
public partial class App : Application

2
sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml.cs

@ -1,4 +1,4 @@
#if IOS || WINDOWS
#if IOS || MACCATALYST || WINDOWS
namespace OpenIddict.Sandbox.Maui.Client;
public partial class AppShell : Shell

2
sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml.cs

@ -1,4 +1,4 @@
#if IOS || WINDOWS
#if IOS || MACCATALYST || WINDOWS
using OpenIddict.Abstractions;
using OpenIddict.Client;
using static OpenIddict.Abstractions.OpenIddictConstants;

2
sandbox/OpenIddict.Sandbox.Maui.Client/MauiHostApplicationLifetime.cs

@ -1,4 +1,4 @@
#if IOS || WINDOWS
#if IOS || MACCATALYST || WINDOWS
using Microsoft.Extensions.Hosting;
namespace OpenIddict.Sandbox.Maui.Client;

2
sandbox/OpenIddict.Sandbox.Maui.Client/MauiHostedServiceAdapter.cs

@ -1,4 +1,4 @@
#if IOS || WINDOWS
#if IOS || MACCATALYST || WINDOWS
using Microsoft.Extensions.Hosting;
namespace OpenIddict.Sandbox.Maui.Client;

2
sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs

@ -1,4 +1,4 @@
#if IOS || WINDOWS
#if IOS || MACCATALYST || WINDOWS
using System.Net.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;

1
sandbox/OpenIddict.Sandbox.Maui.Client/OpenIddict.Sandbox.Maui.Client.csproj

@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFrameworks Condition=" '$(SupportsWindowsPlatformTargeting)' == 'true' ">net8.0-windows10.0.19041</TargetFrameworks>
<TargetFrameworks Condition=" '$(SupportsIOSPlatformTargeting)' == 'true' ">$(TargetFrameworks);net8.0-ios17.2</TargetFrameworks>
<TargetFrameworks Condition=" '$(SupportsMacCatalystPlatformTargeting)' == 'true' ">$(TargetFrameworks);net8.0-maccatalyst17.2</TargetFrameworks>
<UseMaui Condition=" '$(TargetFrameworks)' != '' ">true</UseMaui>
<TargetFrameworks Condition=" '$(TargetFrameworks)' == '' ">net8.0</TargetFrameworks>
<SingleProject>true</SingleProject>

11
sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/AppDelegate.cs

@ -0,0 +1,11 @@
#if MACCATALYST
using Foundation;
namespace OpenIddict.Sandbox.Maui.Client;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
#endif

14
sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/Entitlements.plist

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<false/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

38
sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/Info.plist

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- The Mac App Store requires you specify if the app uses encryption. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/itsappusesnonexemptencryption -->
<!-- <key>ITSAppUsesNonExemptEncryption</key> -->
<!-- Please indicate <true/> or <false/> here. -->
<!-- Specify the category for your app here. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationcategorytype -->
<!-- <key>LSApplicationCategoryType</key> -->
<!-- <string>public.app-category.YOUR-CATEGORY-HERE</string> -->
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>

11
sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/MacCatalyst/Program.cs

@ -0,0 +1,11 @@
#if MACCATALYST
using ObjCRuntime;
using UIKit;
namespace OpenIddict.Sandbox.Maui.Client;
public static class Program
{
public static void Main(string[] args) => UIApplication.Main(args, null, typeof(AppDelegate));
}
#endif

4
sandbox/OpenIddict.Sandbox.Maui.Client/Program.cs

@ -1,3 +1,3 @@
#if !IOS && !WINDOWS
Console.Error.WriteLine("This sample is only supported on iOS and Windows.");
#if !IOS && !MACCATALYST && !WINDOWS
Console.Error.WriteLine("This sample is only supported on iOS, Mac Catalyst and Windows.");
#endif

2
sandbox/OpenIddict.Sandbox.Maui.Client/Worker.cs

@ -1,4 +1,4 @@
#if IOS || WINDOWS
#if IOS || MACCATALYST || WINDOWS
using Microsoft.EntityFrameworkCore;
namespace OpenIddict.Sandbox.Maui.Client;

6
src/OpenIddict.Client.SystemIntegration/OpenIddict.Client.SystemIntegration.csproj

@ -5,6 +5,8 @@
$(NetFrameworkTargetFrameworks);
$(NetCoreTargetFrameworks);
$(NetCoreIOSTargetFrameworks);
$(NetCoreMacCatalystTargetFrameworks);
$(NetCoreMacOSTargetFrameworks);
$(NetCoreWindowsTargetFrameworks);
$(NetStandardTargetFrameworks);
$(UniversalWindowsPlatformTargetFrameworks)
@ -14,7 +16,7 @@
<PropertyGroup>
<Description>Operating system integration package for the OpenIddict client.</Description>
<PackageTags>$(PackageTags);client;ios;linux;windows</PackageTags>
<PackageTags>$(PackageTags);client;ios;linux;maccatalyst;macos;windows</PackageTags>
</PropertyGroup>
<ItemGroup>
@ -54,6 +56,8 @@
<SupportedPlatform Remove="@(SupportedPlatform)" />
<SupportedPlatform Include="ios" />
<SupportedPlatform Include="linux" />
<SupportedPlatform Include="maccatalyst" />
<SupportedPlatform Include="macos" />
<SupportedPlatform Include="windows" />
</ItemGroup>

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

@ -32,5 +32,7 @@ public enum OpenIddictClientSystemIntegrationAuthenticationMode
/// AS web authentication session-based authentication and logout.
/// </summary>
[SupportedOSPlatform("ios12.0")]
[SupportedOSPlatform("maccatalyst13.0")]
[SupportedOSPlatform("macos10.15")]
ASWebAuthenticationSession = 2
}

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

@ -54,6 +54,8 @@ public sealed class OpenIddictClientSystemIntegrationBuilder
/// </summary>
/// <returns>The <see cref="OpenIddictClientSystemIntegrationBuilder"/>.</returns>
[SupportedOSPlatform("ios12.0")]
[SupportedOSPlatform("maccatalyst13.0")]
[SupportedOSPlatform("macos10.15")]
public OpenIddictClientSystemIntegrationBuilder UseASWebAuthenticationSession()
{
if (!OpenIddictClientSystemIntegrationHelpers.IsASWebAuthenticationSessionSupported())

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

@ -74,8 +74,10 @@ public sealed class OpenIddictClientSystemIntegrationConfiguration : IConfigureO
throw new ArgumentNullException(nameof(options));
}
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));

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

@ -31,8 +31,10 @@ public static class OpenIddictClientSystemIntegrationExtensions
throw new ArgumentNullException(nameof(builder));
}
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Create("maccatalyst")) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
throw new PlatformNotSupportedException(SR.GetResourceString(SR.ID0389));

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

@ -30,7 +30,7 @@ public static class OpenIddictClientSystemIntegrationHandlerFilters
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_AUTHENTICATION_SERVICES
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (OpenIddictClientSystemIntegrationHelpers.IsASWebAuthenticationSessionSupported())
{
return new(ContainsASWebAuthenticationSessionResult(context.Transaction));

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

@ -16,6 +16,16 @@ using OpenIddict.Extensions;
using AuthenticationServices;
#endif
#if SUPPORTS_FOUNDATION
using Foundation;
#endif
#if SUPPORTS_APPKIT
using NativeWindow = AppKit.NSWindow;
#elif SUPPORTS_UIKIT
using NativeWindow = UIKit.UIWindow;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
using Windows.Security.Authentication.Web;
using Windows.UI.Core;
@ -90,7 +100,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
#if SUPPORTS_AUTHENTICATION_SERVICES
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.RedirectUri))
{
return;
@ -141,7 +151,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
// which the Safari web view will be attached MUST be provided (otherwise, a code 2
// error is returned by ASWebAuthenticationSession). To avoid that, a default provider
// pointing to the current UI window is automatically attached on iOS 13.0 and higher.
if (OpenIddictClientSystemIntegrationHelpers.IsIOSVersionAtLeast(13))
if (OperatingSystem.IsIOSVersionAtLeast(13))
{
#pragma warning disable CA1416
session.PresentationContextProvider = new ASWebAuthenticationPresentationContext(
@ -199,10 +209,10 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
}
#if SUPPORTS_AUTHENTICATION_SERVICES
class ASWebAuthenticationPresentationContext(UIWindow window) : NSObject,
class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject,
IASWebAuthenticationPresentationContextProviding
{
UIWindow IASWebAuthenticationPresentationContextProviding.GetPresentationAnchor(
NativeWindow IASWebAuthenticationPresentationContextProviding.GetPresentationAnchor(
ASWebAuthenticationSession session) => window;
}
#endif
@ -405,9 +415,14 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
}
}
#if SUPPORTS_UIKIT
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
await OpenIddictClientSystemIntegrationHelpers.TryLaunchBrowserWithUIApplicationAsync(uri))
#if SUPPORTS_APPKIT
if (OperatingSystem.IsMacOS() && await OpenIddictClientSystemIntegrationHelpers.TryLaunchBrowserWithNSWorkspaceAsync(uri))
{
context.HandleRequest();
return;
}
#elif SUPPORTS_UIKIT
if (OperatingSystem.IsIOS() && await OpenIddictClientSystemIntegrationHelpers.TryLaunchBrowserWithUIApplicationAsync(uri))
{
context.HandleRequest();
return;

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

@ -16,6 +16,16 @@ using OpenIddict.Extensions;
using AuthenticationServices;
#endif
#if SUPPORTS_FOUNDATION
using Foundation;
#endif
#if SUPPORTS_APPKIT
using NativeWindow = AppKit.NSWindow;
#elif SUPPORTS_UIKIT
using NativeWindow = UIKit.UIWindow;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
using Windows.Security.Authentication.Web;
using Windows.UI.Core;
@ -90,7 +100,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
Debug.Assert(context.Transaction.Request is not null, SR.GetResourceString(SR.ID4008));
#if SUPPORTS_AUTHENTICATION_SERVICES
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
{
return;
@ -141,7 +151,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
// which the Safari web view will be attached MUST be provided (otherwise, a code 2
// error is returned by ASWebAuthenticationSession). To avoid that, a default provider
// pointing to the current UI window is automatically attached on iOS 13.0 and higher.
if (OpenIddictClientSystemIntegrationHelpers.IsIOSVersionAtLeast(13))
if (OperatingSystem.IsIOSVersionAtLeast(13))
{
#pragma warning disable CA1416
session.PresentationContextProvider = new ASWebAuthenticationPresentationContext(
@ -198,10 +208,10 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
}
#if SUPPORTS_AUTHENTICATION_SERVICES
class ASWebAuthenticationPresentationContext(UIWindow window) : NSObject,
class ASWebAuthenticationPresentationContext(NativeWindow window) : NSObject,
IASWebAuthenticationPresentationContextProviding
{
UIWindow IASWebAuthenticationPresentationContextProviding.GetPresentationAnchor(
NativeWindow IASWebAuthenticationPresentationContextProviding.GetPresentationAnchor(
ASWebAuthenticationSession session) => window;
}
#endif
@ -404,9 +414,14 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
}
}
#if SUPPORTS_UIKIT
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ios")) &&
await OpenIddictClientSystemIntegrationHelpers.TryLaunchBrowserWithUIApplicationAsync(uri))
#if SUPPORTS_APPKIT
if (OperatingSystem.IsMacOS() && await OpenIddictClientSystemIntegrationHelpers.TryLaunchBrowserWithNSWorkspaceAsync(uri))
{
context.HandleRequest();
return;
}
#elif SUPPORTS_UIKIT
if (OperatingSystem.IsIOS() && await OpenIddictClientSystemIntegrationHelpers.TryLaunchBrowserWithUIApplicationAsync(uri))
{
context.HandleRequest();
return;

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

@ -24,6 +24,10 @@ using static OpenIddict.Client.SystemIntegration.OpenIddictClientSystemIntegrati
using IHostApplicationLifetime = Microsoft.Extensions.Hosting.IApplicationLifetime;
#endif
#if SUPPORTS_FOUNDATION
using Foundation;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
using Windows.Security.Authentication.Web;
#endif
@ -231,7 +235,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_AUTHENTICATION_SERVICES
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
(context.BaseUri, context.RequestUri) = context.Transaction.GetASWebAuthenticationCallbackUrl() switch
{
NSUrl url when Uri.TryCreate(url.AbsoluteString, UriKind.Absolute, out Uri? uri) => (
@ -642,7 +646,7 @@ public static partial class OpenIddictClientSystemIntegrationHandlers
throw new ArgumentNullException(nameof(context));
}
#if SUPPORTS_AUTHENTICATION_SERVICES
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
if (context.Transaction.GetASWebAuthenticationCallbackUrl()
is not NSUrl url || !Uri.TryCreate(url.AbsoluteString, UriKind.Absolute, out Uri? uri))
{

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

@ -13,6 +13,17 @@ using System.Runtime.Versioning;
using System.Security.Principal;
using OpenIddict.Extensions;
#if SUPPORTS_FOUNDATION
using Foundation;
#endif
#if SUPPORTS_APPKIT
using AppKit;
using NativeWindow = AppKit.NSWindow;
#elif SUPPORTS_UIKIT
using NativeWindow = UIKit.UIWindow;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel;
@ -44,13 +55,15 @@ public static class OpenIddictClientSystemIntegrationHelpers
public static HttpListenerContext? GetHttpListenerContext(this OpenIddictClientTransaction transaction)
=> transaction.GetProperty<HttpListenerContext>(typeof(HttpListenerContext).FullName!);
#if SUPPORTS_AUTHENTICATION_SERVICES
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
/// <summary>
/// Gets the AS web authentication callback URL associated with the current context.
/// </summary>
/// <param name="transaction">The transaction instance.</param>
/// <returns>The <see cref="NSUrl"/> instance or <see langword="null"/> if it couldn't be found.</returns>
[SupportedOSPlatform("ios12.0")]
[SupportedOSPlatform("maccatalyst13.0")]
[SupportedOSPlatform("macos10.15")]
public static NSUrl? GetASWebAuthenticationCallbackUrl(this OpenIddictClientTransaction transaction)
=> transaction.GetProperty<NSUrl>(typeof(NSUrl).FullName!);
#endif
@ -66,27 +79,6 @@ public static class OpenIddictClientSystemIntegrationHelpers
=> transaction.GetProperty<WebAuthenticationResult>(typeof(WebAuthenticationResult).FullName!);
#endif
/// <summary>
/// Determines whether the current iOS version
/// is greater than or equals to the specified version.
/// </summary>
/// <returns>
/// <see langword="true"/> if the current iOS version is greater than
/// or equals to the specified version, <see langword="false"/> otherwise.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SupportedOSPlatformGuard("ios")]
internal static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0)
{
#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
return OperatingSystem.IsIOSVersionAtLeast(major, minor, build);
#else
return RuntimeInformation.OSDescription.StartsWith("iOS ", StringComparison.OrdinalIgnoreCase) &&
RuntimeInformation.OSDescription["iOS ".Length..] is string value &&
Version.TryParse(value, out Version? version) && version >= new Version(major, minor, build);
#endif
}
/// <summary>
/// Determines whether the current Windows version
/// is greater than or equals to the specified version.
@ -125,7 +117,16 @@ public static class OpenIddictClientSystemIntegrationHelpers
/// <returns><see langword="true"/> if the ASWebAuthenticationSession API is supported, <see langword="false"/> otherwise.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SupportedOSPlatformGuard("ios12.0")]
internal static bool IsASWebAuthenticationSessionSupported() => IsIOSVersionAtLeast(12);
[SupportedOSPlatformGuard("maccatalyst13.0")]
[SupportedOSPlatformGuard("macos10.15")]
internal static bool IsASWebAuthenticationSessionSupported()
#if SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
=> OperatingSystem.IsIOSVersionAtLeast(12) ||
OperatingSystem.IsMacCatalystVersionAtLeast(13) ||
OperatingSystem.IsMacOSVersionAtLeast(10, 15);
#else
=> false;
#endif
/// <summary>
/// Determines whether the Windows Runtime APIs are supported on this platform.
@ -250,11 +251,14 @@ public static class OpenIddictClientSystemIntegrationHelpers
#if SUPPORTS_PRESENTATION_CONTEXT_PROVIDER
/// <summary>
/// Gets a reference to the current <see cref="UIWindow"/>.
/// Gets a reference to the current <see cref="NativeWindow"/>.
/// </summary>
/// <returns>The <see cref="UIWindow"/> or <see langword="null"/> if it couldn't be resolved.</returns>
internal static UIWindow? GetCurrentUIWindow()
/// <returns>The <see cref="NativeWindow"/> or <see langword="null"/> if it couldn't be resolved.</returns>
internal static NativeWindow? GetCurrentUIWindow()
{
#if SUPPORTS_APPKIT
return NSApplication.SharedApplication.KeyWindow;
#elif SUPPORTS_UIKIT
var window = GetKeyWindow();
if (window is not null && window.WindowLevel == UIWindowLevel.Normal)
{
@ -269,7 +273,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
static UIWindow? GetKeyWindow()
{
if (IsIOSVersionAtLeast(13))
if (OperatingSystem.IsIOSVersionAtLeast(13))
{
try
{
@ -292,7 +296,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
static UIWindow[]? GetWindows()
{
if (IsIOSVersionAtLeast(13))
if (OperatingSystem.IsIOSVersionAtLeast(13))
{
try
{
@ -312,6 +316,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
return UIApplication.SharedApplication.Windows;
}
#endif
}
#endif
@ -344,7 +349,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
/// <param name="uri">The <see cref="Uri"/> to use.</param>
/// <returns><see langword="true"/> if the browser could be started, <see langword="false"/> otherwise.</returns>
[MethodImpl(MethodImplOptions.NoInlining), SupportedOSPlatform("windows10.0.17763")]
internal static async Task<bool> TryLaunchBrowserWithWindowsRuntimeAsync(Uri uri)
internal static async ValueTask<bool> TryLaunchBrowserWithWindowsRuntimeAsync(Uri uri)
{
// Note: with the materialization of Project Centennial/Desktop Bridge in Windows 10 1607
// (also known as Anniversary Update), desktop applications that don't have a package
@ -393,7 +398,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
/// <returns><see langword="true"/> if the browser could be started, <see langword="false"/> otherwise.</returns>
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("windows")]
internal static async Task<bool> TryLaunchBrowserWithShellExecuteAsync(Uri uri)
internal static async ValueTask<bool> TryLaunchBrowserWithShellExecuteAsync(Uri uri)
{
try
{
@ -417,15 +422,26 @@ public static class OpenIddictClientSystemIntegrationHelpers
}
}
#if SUPPORTS_APPKIT
/// <summary>
/// Starts the system browser using <see href="NSWorkspace"/>.
/// </summary>
/// <param name="uri">The <see cref="Uri"/> to use.</param>
/// <returns><see langword="true"/> if the browser could be started, <see langword="false"/> otherwise.</returns>
[SupportedOSPlatform("macos")]
internal static ValueTask<bool> TryLaunchBrowserWithNSWorkspaceAsync(Uri uri)
=> new(NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(uri.AbsoluteUri)));
#endif
#if SUPPORTS_UIKIT
/// <summary>
/// Starts the system browser using xdg-open.
/// Starts the system browser using <see href="UIApplication"/>.
/// </summary>
/// <param name="uri">The <see cref="Uri"/> to use.</param>
/// <returns><see langword="true"/> if the browser could be started, <see langword="false"/> otherwise.</returns>
[SupportedOSPlatform("ios")]
internal static Task<bool> TryLaunchBrowserWithUIApplicationAsync(Uri uri)
=> UIApplication.SharedApplication.OpenUrlAsync(new NSUrl(uri.AbsoluteUri), new UIApplicationOpenUrlOptions());
internal static ValueTask<bool> TryLaunchBrowserWithUIApplicationAsync(Uri uri)
=> new(UIApplication.SharedApplication.OpenUrlAsync(new NSUrl(uri.AbsoluteUri), new UIApplicationOpenUrlOptions()));
#endif
/// <summary>
@ -434,7 +450,7 @@ public static class OpenIddictClientSystemIntegrationHelpers
/// <param name="uri">The <see cref="Uri"/> to use.</param>
/// <returns><see langword="true"/> if the browser could be started, <see langword="false"/> otherwise.</returns>
[SupportedOSPlatform("linux")]
internal static async Task<bool> TryLaunchBrowserWithXdgOpenAsync(Uri uri)
internal static async ValueTask<bool> TryLaunchBrowserWithXdgOpenAsync(Uri uri)
{
try
{

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

@ -12,6 +12,10 @@ using System.Security.Principal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
#if SUPPORTS_FOUNDATION
using Foundation;
#endif
#if SUPPORTS_WINDOWS_RUNTIME
using Windows.Security.Authentication.Web;
#endif
@ -64,7 +68,7 @@ public sealed class OpenIddictClientSystemIntegrationService
internal Task HandleHttpRequestAsync(HttpListenerContext request, CancellationToken cancellationToken = default)
=> HandleRequestAsync(request ?? throw new ArgumentNullException(nameof(request)), cancellationToken);
#if SUPPORTS_AUTHENTICATION_SERVICES
#if SUPPORTS_AUTHENTICATION_SERVICES && SUPPORTS_FOUNDATION
/// <summary>
/// Handles the specified AS web authentication session callback URL.
/// </summary>
@ -73,6 +77,8 @@ public sealed class OpenIddictClientSystemIntegrationService
/// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException"><paramref name="url"/> is <see langword="null"/>.</exception>
[SupportedOSPlatform("ios12.0")]
[SupportedOSPlatform("maccatalyst13.0")]
[SupportedOSPlatform("macos10.15")]
internal Task HandleASWebAuthenticationCallbackUrlAsync(NSUrl url, CancellationToken cancellationToken = default)
=> HandleRequestAsync(url, cancellationToken);
#endif

2
src/OpenIddict/OpenIddict.csproj

@ -5,6 +5,8 @@
$(NetFrameworkTargetFrameworks);
$(NetCoreTargetFrameworks);
$(NetCoreIOSTargetFrameworks);
$(NetCoreMacCatalystTargetFrameworks);
$(NetCoreMacOSTargetFrameworks);
$(NetCoreWindowsTargetFrameworks);
$(NetStandardTargetFrameworks);
$(UniversalWindowsPlatformTargetFrameworks)

Loading…
Cancel
Save