Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial changes to add support for .NET MAUI #3262

Closed
wants to merge 8 commits into from

Conversation

bgavrilMS
Copy link
Member

@bgavrilMS bgavrilMS commented Apr 4, 2022

MAUI support - #3127

Blocking issues:

  1. MacCatalyst KeyChain access issue - [Security] Expose kSecurityUseDataProtectionKeychain in the SecRecord class. xamarin/xamarin-macios#14580 (looks like changes are in, but not yet in Xamarin SDK)
  2. UWP - WebAuthenticationBroker API that supports all WinAppSDK OS's and application types microsoft/WindowsAppSDK#441 (we could ask ppl to use WAM until this is fixed)

@VladislavAntonyuk
Copy link

you probably need to install .NET MAUI Workloads to build the lib: dotnet workloads install maui

@Csaba8472
Copy link

hello, I had to make the necessary changes to make MSAL work on .net6 for one of my MAUI app (ios, android). I made it for internal use (please don't judge the code :) ), however when I saw you're working on maui support, I thought I share it. I also had to recompile Xamarin.Google.Guava.ListenableFuture but I think the latest version(1.0.0.7) should be fine. Please let me know if there is anything I could do with my branch, to make it useful for you.

@nickrandolph
Copy link

Hi all, what's the progress on this PR? It's mindboggling that Maui has shipped and that there's no MSAL support 🤦‍♂️

@billyjacobs2014
Copy link

billyjacobs2014 commented Jul 4, 2022

Hi all, what's the progress on this PR? It's mindboggling that Maui has shipped and that there's no MSAL support 🤦‍♂️
I also would like to know the status of this. How is it possible that ios is still not supported. Adding the latest version of this library causes the build to fail when targeting ios. This has been an known issue since early April, prior to the release of .net maui and the fact that ios is not supported 2 months after release is hard to believe.

@@ -17,7 +17,7 @@ public HttpClient GetHttpClient()

var httpClient = new HttpClient(
// As per Xamarin guidance https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/http-stack?tabs=windows
new Xamarin.Android.Net.AndroidClientHandler());
new Xamarin.Android.Net.AndroidMessageHandler());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SameerK-MSFT - shouldn't this be added only to MAUI?

@@ -12,14 +12,6 @@
<PropertyGroup Condition="'$(MSAL_DESKTOP_ONLY_DEV)' == ''">

<TargetFrameworkNetStandard>netstandard1.3</TargetFrameworkNetStandard>
<TargetFrameworkNetDesktop45>net45</TargetFrameworkNetDesktop45>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo this, we cannot remove legacy frameworks, except maybe net45. I'd prefer to remove net45 in a separate commit.


<!-- net6.0 (MAUI) -->
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net6.0-'))">
<DefineConstants>$(DefineConstants);MAUI</DefineConstants>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this constant - use NET6 if applicable to all net6 platforms. Otherwise use a platform specific constant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, net6-android/ios/maccatalyst are quite different than net6. For example we don't expose Confidential Client flows on mobile / desktop targets, because servers don't run there. So we do need a target.

But generally, I gree that we should remove this constnant. We should use constants like SUPPORTS_CONFIDENTIAL_CLIENT etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you call this constant XAMARIN or MOBILE. Choosing the word MAUI assumes the exclusion of the xamarin native platforms or other tools in the ecosystem such as Uno Platform, Avalonia, etc.

@SkyeHoefling
Copy link

I pulled this code to see how well it works with Uno Platform .NET 6 and WinUI

  • Android - Works ✅
  • iOS - Works ✅
  • MacOS - Fails ❌

I am not sure what is going on with MacOS as the debugging experience is a little lacking when launching it from the .NET CLI but it fails to load the login window. I took the exact same code and loaded it into the older style Xamarin macOS projects (pre-net6) and it worked as expected using v4.39.0

@bgavrilMS
Copy link
Member Author

A similar PR was merged yesterday with support for net6-android net6-ios and net6-maccatalyst. CLosing this one.

@bgavrilMS bgavrilMS closed this Jul 8, 2022
@DRAirey1
Copy link

DRAirey1 commented Aug 23, 2022

I built a simple Maui solution directly from the Visual Studio template. I added the Microsoft.Identity.Client NuGet package and added this code to MainPage.xaml.cs:

        var signInApplication = PublicClientApplicationBuilder
            .Create("some-client-id")
            .WithIosKeychainSecurityGroup("com.microsoft.adalcache")
            .WithRedirectUri("msal6a7fefdb-47b3-4a25-87a3-593c12a4115b://auth")
            .WithB2CAuthority(@"https://thetarexproduction.b2clogin.com/tfp/thetarexproduction.onmicrosoft.com/B2C_1_SignIn")
            .Build();
        var accounts = await signInApplication.GetAccountsAsync("B2C_1_SignIn").ConfigureAwait(false);
        string[] scopes = new string[] { "some-read-scope", "some-write-scope" };
        AuthenticationResult authenticationResult = await signInApplication.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
            .ExecuteAsync(CancellationToken.None)
            .ConfigureAwait(false);
        this.User = authenticationResult.ClaimsPrincipal;

Got this error:

1>Tool xcrun execution finished (exit code = 1).
1>ld: framework not found System
1>clang: error: linker command failed with exit code 1 (use -v to see invocation)
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.446-ci.-release-6-0-4xx.446\targets\Xamarin.Shared.Sdk.targets(1219,3): error : clang++ exited with code 1
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.446-ci.-release-6-0-4xx.446\targets\Xamarin.Shared.Sdk.targets(1219,3): error :
1>Done building project "MauiApp2.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have all the latest NuGet packages, even tried looking for pre-releases.
How can you release Maui with no ability to log in cloud applications? When will we see a fix for this?

@DRAirey1
Copy link

DRAirey1 commented Aug 24, 2022

hello, I had to make the necessary changes to make MSAL work on .net6 for one of my MAUI app (ios, android). I made it for internal use (please don't judge the code :) ), however when I saw you're working on maui support, I thought I share it. I also had to recompile Xamarin.Google.Guava.ListenableFuture but I think the latest version(1.0.0.7) should be fine. Please let me know if there is anything I could do with my branch, to make it useful for you.

I'm unable to build from your repository. Is there any chance you can either post instructions on how to build, or actually publish the NuGet package?

@bgavrilMS
Copy link
Member Author

@DRAirey1 - you don't need to build MSAL manually, we have a preview version published to nuget - https://www.nuget.org/packages/Microsoft.Identity.Client/4.46.0-preview2

And a rough sample: https://github.com/Azure-Samples/active-directory-xamarin-native-v2/tree/main/MAUI

@DRAirey1
Copy link

Alright. That seems to have compiled and linked. Thanks.

@bgavrilMS bgavrilMS deleted the mikeparker104/maui branch April 25, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants