From 5c615e1d0c315d6cff7495c916a5358dab30a603 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Thu, 15 Aug 2024 11:15:32 +0200 Subject: [PATCH 1/4] fix: Exclude Microsoft.Graph for local iOS build Workaroud for https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2617 --- .../SamplesApp.netcoremobile.csproj | 2 +- .../Msal/MsalLoginAndGraph.xaml.cs | 24 ++++++++++++++++--- ...erElement_Original_MsAppdataSource.xaml.cs | 1 - 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/SamplesApp/SamplesApp.netcoremobile/SamplesApp.netcoremobile.csproj b/src/SamplesApp/SamplesApp.netcoremobile/SamplesApp.netcoremobile.csproj index 69f34508e484..c80cf74aad71 100644 --- a/src/SamplesApp/SamplesApp.netcoremobile/SamplesApp.netcoremobile.csproj +++ b/src/SamplesApp/SamplesApp.netcoremobile/SamplesApp.netcoremobile.csproj @@ -188,7 +188,7 @@ - + 5.56.0 diff --git a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs index 6616acd95b04..66fca59a1dc0 100644 --- a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs @@ -1,11 +1,13 @@ -using System; +#if !DEBUG || !__IOS__ // Workaround for https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2617 +#define DISABLE_GRAPH +#endif +using System; using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -using Microsoft.Graph; using Microsoft.Identity.Client; using Microsoft.Kiota.Abstractions; using Microsoft.Kiota.Abstractions.Authentication; @@ -15,12 +17,19 @@ using Uno.UI.MSAL; using Uno.UI.Samples.Controls; using Prompt = Microsoft.Identity.Client.Prompt; +#if !DISABLE_GRAPH +using Microsoft.Graph; +#endif namespace UITests.Msal { [Sample("MSAL", IgnoreInSnapshotTests = true)] - public sealed partial class MsalLoginAndGraph : Page, IAuthenticationProvider + public sealed partial class MsalLoginAndGraph : Page, +#if !DISABLE_GRAPH + IAuthenticationProvider +#endif { +#if !DISABLE_GRAPH private const string CLIENT_ID = "a74f513b-2d8c-45c0-a15a-15e63f7a7862"; private const string TENANT_ID = "6d53ef61-b6d1-4150-ae0b-43b90e75e0cd"; @@ -37,31 +46,37 @@ public sealed partial class MsalLoginAndGraph : Page, IAuthenticationProvider private readonly string[] SCOPES = new[] { "https://graph.microsoft.com/User.Read", "https://graph.microsoft.com/email", "https://graph.microsoft.com/profile" }; private readonly IPublicClientApplication _app; +#endif public MsalLoginAndGraph() { this.InitializeComponent(); +#if !DISABLE_GRAPH _app = PublicClientApplicationBuilder .Create(CLIENT_ID) .WithTenantId(TENANT_ID) .WithRedirectUri(REDIRECT_URI) .WithUnoHelpers() .Build(); +#endif } private async void SignIn(object sender, RoutedEventArgs e) { +#if !DISABLE_GRAPH var result = await _app.AcquireTokenInteractive(SCOPES) .WithPrompt(Prompt.SelectAccount) .WithUnoHelpers() .ExecuteAsync(); tokenBox.Text = result.AccessToken; +#endif } private async void LoadFromGraph(object sender, RoutedEventArgs e) { +#if !DISABLE_GRAPH var httpClient = new HttpClient(); var client = new GraphServiceClient(httpClient, this); @@ -89,12 +104,15 @@ private async void LoadFromGraph(object sender, RoutedEventArgs e) { Console.Error.WriteLine(exception); } +#endif } +#if !DISABLE_GRAPH Task IAuthenticationProvider.AuthenticateRequestAsync(RequestInformation request, Dictionary additionalAuthenticationContext, CancellationToken cancellationToken) { request.Headers.Add("Authorization", $"Bearer {tokenBox.Text}"); return Task.CompletedTask; } +#endif } } diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/MediaPlayerElement/MediaPlayerElement_Original_MsAppdataSource.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/MediaPlayerElement/MediaPlayerElement_Original_MsAppdataSource.xaml.cs index c06b51397c0f..9816e8c9af47 100644 --- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/MediaPlayerElement/MediaPlayerElement_Original_MsAppdataSource.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/MediaPlayerElement/MediaPlayerElement_Original_MsAppdataSource.xaml.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; -using Microsoft.Graph; using Uno.UI.Samples.Controls; using Windows.Foundation; using Windows.Foundation.Collections; From f8be28243bea30041ea9830b8248b04ed9c5adb1 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Thu, 15 Aug 2024 11:31:00 +0200 Subject: [PATCH 2/4] chore: Adjust --- src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs index 66fca59a1dc0..2bad3e9b1e61 100644 --- a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs @@ -24,9 +24,9 @@ namespace UITests.Msal { [Sample("MSAL", IgnoreInSnapshotTests = true)] - public sealed partial class MsalLoginAndGraph : Page, + public sealed partial class MsalLoginAndGraph : Page #if !DISABLE_GRAPH - IAuthenticationProvider + , IAuthenticationProvider #endif { #if !DISABLE_GRAPH From a4d083da52dacdd7c7530cff1b3958d1b33356fa Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Thu, 15 Aug 2024 14:00:59 +0200 Subject: [PATCH 3/4] chore: Wrong condition --- .../UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs index 2bad3e9b1e61..a04eeb4a300f 100644 --- a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs @@ -1,4 +1,4 @@ -#if !DEBUG || !__IOS__ // Workaround for https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2617 +#if DEBUG && __IOS__ // Workaround for https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2617 #define DISABLE_GRAPH #endif using System; @@ -9,8 +9,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Identity.Client; -using Microsoft.Kiota.Abstractions; -using Microsoft.Kiota.Abstractions.Authentication; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Imaging; @@ -18,6 +16,8 @@ using Uno.UI.Samples.Controls; using Prompt = Microsoft.Identity.Client.Prompt; #if !DISABLE_GRAPH +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Abstractions.Authentication; using Microsoft.Graph; #endif From 944ae1eb337006fd89cc57eb1699d67d625077c3 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Thu, 15 Aug 2024 14:03:06 +0200 Subject: [PATCH 4/4] chore: Async markers --- .../UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs index a04eeb4a300f..fe4d6157ce6f 100644 --- a/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs @@ -62,7 +62,11 @@ public MsalLoginAndGraph() #endif } - private async void SignIn(object sender, RoutedEventArgs e) + private +#if !DISABLE_GRAPH + async +#endif + void SignIn(object sender, RoutedEventArgs e) { #if !DISABLE_GRAPH var result = await _app.AcquireTokenInteractive(SCOPES) @@ -74,7 +78,11 @@ private async void SignIn(object sender, RoutedEventArgs e) #endif } - private async void LoadFromGraph(object sender, RoutedEventArgs e) + private +#if !DISABLE_GRAPH + async +#endif + void LoadFromGraph(object sender, RoutedEventArgs e) { #if !DISABLE_GRAPH var httpClient = new HttpClient();