From f398b5ff4038fc11796bc4bb3bdc1c6e52646b09 Mon Sep 17 00:00:00 2001 From: Feng Gao Date: Fri, 3 Jan 2025 10:26:38 -0800 Subject: [PATCH 01/16] First commit --- MauiMacAppWithBroker.sln | 22 + .../BrokerExtension.cs | 9 + .../RuntimeBroker.cs | 14 +- .../ApiConfig/BrokerOptions.cs | 9 + .../PlatformsCommon/Shared/DesktopOsHelper.cs | 6 + tests/devapps/MauiMacAppWithBroker/App.xaml | 14 + .../devapps/MauiMacAppWithBroker/App.xaml.cs | 11 + .../MauiMacAppWithBroker/AppShell.xaml | 15 + .../MauiMacAppWithBroker/AppShell.xaml.cs | 9 + .../MauiMacAppWithBroker/MainPage.xaml | 36 ++ .../MauiMacAppWithBroker/MainPage.xaml.cs | 86 ++++ .../MauiMacAppWithBroker.csproj | 79 ++++ .../MauiMacAppWithBroker/MauiProgram.cs | 24 + .../Platforms/MacCatalyst/AppDelegate.cs | 9 + .../Platforms/MacCatalyst/Entitlements.plist | 14 + .../Platforms/MacCatalyst/Info.plist | 38 ++ .../Platforms/MacCatalyst/Program.cs | 15 + .../Properties/launchSettings.json | 8 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107276 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111164 bytes .../Resources/Images/dotnet_bot.png | Bin 0 -> 69811 bytes .../Resources/Raw/AboutAssets.txt | 15 + .../Resources/Splash/splash.svg | 8 + .../Resources/Styles/Colors.xaml | 45 ++ .../Resources/Styles/Styles.xaml | 427 ++++++++++++++++++ 27 files changed, 922 insertions(+), 3 deletions(-) create mode 100644 MauiMacAppWithBroker.sln create mode 100644 tests/devapps/MauiMacAppWithBroker/App.xaml create mode 100644 tests/devapps/MauiMacAppWithBroker/App.xaml.cs create mode 100644 tests/devapps/MauiMacAppWithBroker/AppShell.xaml create mode 100644 tests/devapps/MauiMacAppWithBroker/AppShell.xaml.cs create mode 100644 tests/devapps/MauiMacAppWithBroker/MainPage.xaml create mode 100644 tests/devapps/MauiMacAppWithBroker/MainPage.xaml.cs create mode 100644 tests/devapps/MauiMacAppWithBroker/MauiMacAppWithBroker.csproj create mode 100644 tests/devapps/MauiMacAppWithBroker/MauiProgram.cs create mode 100644 tests/devapps/MauiMacAppWithBroker/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 tests/devapps/MauiMacAppWithBroker/Platforms/MacCatalyst/Entitlements.plist create mode 100644 tests/devapps/MauiMacAppWithBroker/Platforms/MacCatalyst/Info.plist create mode 100644 tests/devapps/MauiMacAppWithBroker/Platforms/MacCatalyst/Program.cs create mode 100644 tests/devapps/MauiMacAppWithBroker/Properties/launchSettings.json create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/AppIcon/appicon.svg create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/AppIcon/appiconfg.svg create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/Images/dotnet_bot.png create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/Raw/AboutAssets.txt create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/Splash/splash.svg create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/Styles/Colors.xaml create mode 100644 tests/devapps/MauiMacAppWithBroker/Resources/Styles/Styles.xaml diff --git a/MauiMacAppWithBroker.sln b/MauiMacAppWithBroker.sln new file mode 100644 index 0000000000..7bdfa44eb4 --- /dev/null +++ b/MauiMacAppWithBroker.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MauiMacAppWithBroker", "tests\devapps\MauiMacAppWithBroker\MauiMacAppWithBroker.csproj", "{C0EBA279-7647-42B1-ACEA-B9CC95E2DE18}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C0EBA279-7647-42B1-ACEA-B9CC95E2DE18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0EBA279-7647-42B1-ACEA-B9CC95E2DE18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0EBA279-7647-42B1-ACEA-B9CC95E2DE18}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0EBA279-7647-42B1-ACEA-B9CC95E2DE18}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/client/Microsoft.Identity.Client.Broker/BrokerExtension.cs b/src/client/Microsoft.Identity.Client.Broker/BrokerExtension.cs index 256d3427c8..6520b32035 100644 --- a/src/client/Microsoft.Identity.Client.Broker/BrokerExtension.cs +++ b/src/client/Microsoft.Identity.Client.Broker/BrokerExtension.cs @@ -80,6 +80,15 @@ private static void AddRuntimeSupport(PublicClientApplicationBuilder builder) return new RuntimeBroker(uiParent, appConfig, logger); }; } + else if (DesktopOsHelper.IsDarwin()) + { + builder.Config.BrokerCreatorFunc = + (uiParent, appConfig, logger) => + { + logger.Info("[Runtime] macOS supports broker."); + return new RuntimeBroker(uiParent, appConfig, logger); + }; + } else { builder.Config.BrokerCreatorFunc = diff --git a/src/client/Microsoft.Identity.Client.Broker/RuntimeBroker.cs b/src/client/Microsoft.Identity.Client.Broker/RuntimeBroker.cs index ee9292f83b..e20a9ab32c 100644 --- a/src/client/Microsoft.Identity.Client.Broker/RuntimeBroker.cs +++ b/src/client/Microsoft.Identity.Client.Broker/RuntimeBroker.cs @@ -100,7 +100,15 @@ public RuntimeBroker( s_lazyCore.Value.EnablePii(_logger.PiiLoggingEnabled); } - _parentHandle = GetParentWindow(uiParent); + if (DesktopOsHelper.IsWindows()) + { + _parentHandle = GetParentWindow(uiParent); + } + else + { + // TODO:ADO 3055958 Parent window handle support on mac + _parentHandle = (IntPtr)1; + } // Broker options cannot be null _wamOptions = appConfig.BrokerOptions; @@ -130,7 +138,7 @@ public async Task AcquireTokenInteractiveAsync( Debug.Assert(s_lazyCore.Value != null, "Should not call this API if MSAL runtime init failed"); //need to provide a handle - if (_parentHandle == IntPtr.Zero) + if (DesktopOsHelper.IsWindows() && _parentHandle == IntPtr.Zero) { throw new MsalClientException( "window_handle_required", @@ -586,7 +594,7 @@ public void HandleInstallUrl(string appLink) public bool IsBrokerInstalledAndInvokable(AuthorityType authorityType) { - if (!DesktopOsHelper.IsWin10OrServerEquivalent()) + if (!DesktopOsHelper.IsWin10OrServerEquivalent() && !DesktopOsHelper.IsDarwin()) { _logger?.Warning("[RuntimeBroker] Not a supported operating system. WAM broker is not available. "); return false; diff --git a/src/client/Microsoft.Identity.Client/ApiConfig/BrokerOptions.cs b/src/client/Microsoft.Identity.Client/ApiConfig/BrokerOptions.cs index 871cacc8ad..9e66c92772 100644 --- a/src/client/Microsoft.Identity.Client/ApiConfig/BrokerOptions.cs +++ b/src/client/Microsoft.Identity.Client/ApiConfig/BrokerOptions.cs @@ -29,6 +29,10 @@ public enum OperatingSystems /// Use broker on Windows OS /// Windows = 0b_0000_0001, // 1 + /// + /// Use broker on Mac OS + /// + Mac = 0b_0000_0010, // 10 } /// @@ -83,6 +87,11 @@ internal bool IsBrokerEnabledOnCurrentOs() return true; } + if (EnabledOn.HasFlag(OperatingSystems.Mac) && DesktopOsHelper.IsDarwin()) + { + return true; + } + return false; } } diff --git a/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/DesktopOsHelper.cs b/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/DesktopOsHelper.cs index a5fc805a46..852ddb1bb2 100644 --- a/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/DesktopOsHelper.cs +++ b/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/DesktopOsHelper.cs @@ -55,6 +55,12 @@ public static bool IsMac() #endif } + public static bool IsDarwin() + { + string OSDescription = RuntimeInformation.OSDescription; + return OSDescription.Contains("Darwin", StringComparison.OrdinalIgnoreCase); + } + /// /// Checks if the OS supports WAM (Web Account Manager) /// WAM Supported OS's are Windows 10 and above for Client, Windows 2019 and above for Server diff --git a/tests/devapps/MauiMacAppWithBroker/App.xaml b/tests/devapps/MauiMacAppWithBroker/App.xaml new file mode 100644 index 0000000000..c45a504a70 --- /dev/null +++ b/tests/devapps/MauiMacAppWithBroker/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/tests/devapps/MauiMacAppWithBroker/App.xaml.cs b/tests/devapps/MauiMacAppWithBroker/App.xaml.cs new file mode 100644 index 0000000000..b8b20eeff4 --- /dev/null +++ b/tests/devapps/MauiMacAppWithBroker/App.xaml.cs @@ -0,0 +1,11 @@ +namespace MauiMacAppWithBroker; + +public partial class App : Application +{ + public App() + { + InitializeComponent(); + + MainPage = new AppShell(); + } +} diff --git a/tests/devapps/MauiMacAppWithBroker/AppShell.xaml b/tests/devapps/MauiMacAppWithBroker/AppShell.xaml new file mode 100644 index 0000000000..b5771780bf --- /dev/null +++ b/tests/devapps/MauiMacAppWithBroker/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/tests/devapps/MauiMacAppWithBroker/AppShell.xaml.cs b/tests/devapps/MauiMacAppWithBroker/AppShell.xaml.cs new file mode 100644 index 0000000000..da2e950c6a --- /dev/null +++ b/tests/devapps/MauiMacAppWithBroker/AppShell.xaml.cs @@ -0,0 +1,9 @@ +namespace MauiMacAppWithBroker; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + } +} diff --git a/tests/devapps/MauiMacAppWithBroker/MainPage.xaml b/tests/devapps/MauiMacAppWithBroker/MainPage.xaml new file mode 100644 index 0000000000..2e00b84bd7 --- /dev/null +++ b/tests/devapps/MauiMacAppWithBroker/MainPage.xaml @@ -0,0 +1,36 @@ + + + + + + + +