Skip to content

Commit

Permalink
fix: Exclude Microsoft.Graph for local iOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 15, 2024
1 parent d00cfe4 commit 5c615e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Graph">
<PackageReference Include="Microsoft.Graph" Condition="'$(Configuration)'!='Debug' or $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))!='ios'"> <!-- Workaround for https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2617 -->
<Version>5.56.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Identity.Client">
Expand Down
24 changes: 21 additions & 3 deletions src/SamplesApp/UITests.Shared/Msal/MsalLoginAndGraph.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";

Expand All @@ -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);

Expand Down Expand Up @@ -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<string, object> additionalAuthenticationContext, CancellationToken cancellationToken)
{
request.Headers.Add("Authorization", $"Bearer {tokenBox.Text}");
return Task.CompletedTask;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5c615e1

Please sign in to comment.