microsoft-authentication-library-for-dotnet icon indicating copy to clipboard operation
microsoft-authentication-library-for-dotnet copied to clipboard

[Feature Request] Make MSAL.NET compatible with MAUI

Open SameerK-MSFT opened this issue 3 years ago • 103 comments

Initial PR to add support: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/pull/3262

  • [x] Add Android and iOS support first
  • [x] Fix the CI build as well
  • [x] Manual testing Android and iOS scenarios (embedded, system and broker)
  • [x] Update xamarin sample

At this point it we should be able to do a partial release with MAUI support for mobile.

  • ~[ ] MacCatalyst support (embedded, system and broker (?) scenario)~ CUT.

MSAL ObjC does not have MacCatalyst support, we will need to coordinate with them on this. Should not block GA of MAUI mobile targets.

  • [x] Net6 (WinUI) support (embedded, system, broker)
  • [x] Update sample ~with MacCatalyst and~ WinUI
  • [ ] Automation tests for ios and android

Maui Status can be found here: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/main/MauiStatus.md

SameerK-MSFT avatar Jan 26 '22 00:01 SameerK-MSFT

Blocked by MAUI previews

bgavrilMS avatar Jan 26 '22 10:01 bgavrilMS

Could you release a preview package targeting net6.0-android/net6.0-ios/net6.0-macos/net6.0-maccatalyst? Just add that targets and create an appropriate package

xperiandri avatar Feb 20 '22 17:02 xperiandri

Build with latest preview

xperiandri avatar Feb 20 '22 17:02 xperiandri

.net6.0-android should be compatible with our current target. .net6.0-ios is undergoing breaking changes and we will need to fix later on. Currently broken. We have not yet tested with mac, but should work.

bgavrilMS avatar Feb 21 '22 09:02 bgavrilMS

using this package into MAUI project, can't deploy to remote mac because of this

ViktorArbuzov avatar Mar 14 '22 12:03 ViktorArbuzov

PR out with some changes, needs review and following changes:

  1. no net6-windows10.xyz target is needed
  2. Update MacCatalyst KeyChain access (see action item on PR)
  3. Build changes
  4. Optional: Drop older monoandroid 9 support.
  5. More testing with embedded / system browser and broker.
  6. Update our Xamarin samples.

bgavrilMS avatar Apr 07 '22 14:04 bgavrilMS

Is this coming soon? MAUI is in RC1 already. Thanks!

emorell96 avatar Apr 13 '22 14:04 emorell96

Yes, there is PR out which provides some support. We've got some trouble on MacCatalyst and also we need to do more testing.

bgavrilMS avatar Apr 13 '22 15:04 bgavrilMS

@bgavrilMS If this is possible, could you please help me to build the dll from the PR? Our project really need's iOS. Thanks!

ViktorArbuzov avatar Apr 19 '22 20:04 ViktorArbuzov

@ViktorArbuzov - if you pull this branch, then edit Microsoft.Identity.Client.csproj and comment out any targets you do not care about (I'd leave at least 2 though), it should build fine. I can get it to build with VS 2022 Preview or via the command line. I recommend you build only Microsoft.Identity.Client.csproj, as the solution files have a ton of tests and sample apps that you don't care about.

image

If you want to pack this into a nuget and use it, you may want to change the version property in the same file. Then dotnet pack.

bgavrilMS avatar Apr 20 '22 15:04 bgavrilMS

@SameerK-MSFT @bgavrilMS is there an update on this feature?

igalfsg avatar Jun 02 '22 15:06 igalfsg

We're hoping to release mobile support soon. Problem we're facing is that ecosystem (VS, AzureDevOps agents etc.) do not support it natively, need to do some build work.

bgavrilMS avatar Jun 02 '22 15:06 bgavrilMS

Exciting. When is it gonna be dished out?

lnaie avatar Jun 05 '22 11:06 lnaie

Any idea on when this will be fixed?

Jeremywhiteley avatar Jun 10 '22 16:06 Jeremywhiteley

Any update on this issue?

nickrandolph avatar Jun 16 '22 07:06 nickrandolph

@nickrandolph @lnaie @Jeremywhiteley if you need it right now, you can build it from the PR, using dotnet pack.

VladislavAntonyuk avatar Jun 16 '22 08:06 VladislavAntonyuk

yeh but we're building libraries for other people that depend on MSAL. Not having net6 support is a bit of an oversight but I get why it was overlooked/delayed given the rushed nature of net6 mobile.

nickrandolph avatar Jun 16 '22 09:06 nickrandolph

We found some problems (missing API) on mobile, which would prevent system browser and broker scenarios. We are discussing this with Maui team.

On a positive note, I tested WinUI and it works well with MSAL 4.44 (already released). No changes needed.

@SameerK-MSFT - please keep this thread updated with progress / blockers etc. Some of the folks here might be able to help.

bgavrilMS avatar Jun 16 '22 13:06 bgavrilMS

@bgavrilMS could you tell which API is missing? Is it an API specific to MAUI or to net6.0-ios or net6.0-android ?

jeromelaban avatar Jun 16 '22 13:06 jeromelaban

Following API is missing from AppDelegate on iOS.

public override bool OpenUrl(UIApplication app, NSUrl url, string sourceApplication, NSObject annotation)

This hook is implemeted by the app developer like here. MSAL uses to this to know if the broker was used or not - see here. We haven't looked into this too much, as this sourceApplication param isn't anyway supported on iOS 13+ (it's empty), so maybe it's not an issue to always ignore it?

The Maui team recommended we use https://gist.github.com/Redth/5be697ac7e75e8d47c26deea83fbc3d0

@SameerK-MSFT is working on this, so pls take my words with a grain of salt...

bgavrilMS avatar Jun 16 '22 13:06 bgavrilMS

@bgavrilMS Thanks. To clarify, are your new changes still going to be including a non-maui net6.0-ios package?

jeromelaban avatar Jun 16 '22 13:06 jeromelaban

What do you mean by non-maui "net6-ios" package? I thought MAUI means net6-ios, net6-android, net6-maccatalyst

Note that MSAL fully supports the vanilla net6 target, e.g. confidential client scenarios and public client desktop scenarios (including WinUI).

bgavrilMS avatar Jun 16 '22 13:06 bgavrilMS

MAUI is a layer on top of the Android/iOS/Catalyst bindings (net6.0-android, net6.0-ios and others). Making a "native" (non-MAUI) app is possible (e.g. Uno Platform uses that specific part) and if you add an explicit dependency to MAUI nuget packages in MSAL, this will become breaking for those frameworks and apps.

jeromelaban avatar Jun 16 '22 14:06 jeromelaban

Following API is missing from AppDelegate on iOS.

public override bool OpenUrl(UIApplication app, NSUrl url, string sourceApplication, NSObject annotation)

This hook is implemeted by the app developer like here. MSAL uses to this to know if the broker was used or not - see here. We haven't looked into this too much, as this sourceApplication param isn't anyway supported on iOS 13+ (it's empty), so maybe it's not an issue to always ignore it?

The Maui team recommended we use https://gist.github.com/Redth/5be697ac7e75e8d47c26deea83fbc3d0

@SameerK-MSFT is working on this, so pls take my words with a grain of salt...

it exists: https://github.com/dotnet/maui/blob/0872cbc326ea8230c24c075d2f98b3195df69765/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs#L80

VladislavAntonyuk avatar Jun 16 '22 14:06 VladislavAntonyuk

MAUI is a layer on top of the Android/iOS/Catalyst bindings (net6.0-android, net6.0-ios and others). Making a "native" (non-MAUI) app is possible (e.g. Uno Platform uses that specific part) and if you add an explicit dependency to MAUI nuget packages in MSAL, this will become breaking for those frameworks and apps.

MAUI != net6 for iOS/Android/Catalyst

just like

Blazor != net6 for WebAssembly

I really wish naming/marketing would support this narrative to bring clarity to developers.

francoistanguay avatar Jun 16 '22 14:06 francoistanguay

Following API is missing from AppDelegate on iOS.

public override bool OpenUrl(UIApplication app, NSUrl url, string sourceApplication, NSObject annotation)

This hook is implemeted by the app developer like here. MSAL uses to this to know if the broker was used or not - see here. We haven't looked into this too much, as this sourceApplication param isn't anyway supported on iOS 13+ (it's empty), so maybe it's not an issue to always ignore it? The Maui team recommended we use https://gist.github.com/Redth/5be697ac7e75e8d47c26deea83fbc3d0 @SameerK-MSFT is working on this, so pls take my words with a grain of salt...

it exists: https://github.com/dotnet/maui/blob/0872cbc326ea8230c24c075d2f98b3195df69765/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs#L80

Notice how it does not have the string sourceApplication param (which was deprecated by Apple in ios 13)

bgavrilMS avatar Jun 16 '22 14:06 bgavrilMS

MAUI is a layer on top of the Android/iOS/Catalyst bindings (net6.0-android, net6.0-ios and others). Making a "native" (non-MAUI) app is possible (e.g. Uno Platform uses that specific part) and if you add an explicit dependency to MAUI nuget packages in MSAL, this will become breaking for those frameworks and apps.

The only dependencies I see are:

<PackageReference Include="System.Security.SecureString" Version="4.3.0" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.4.0" PrivateAssets="All" />

(not sure why we depdend on SecureString, I think it needs to go)

bgavrilMS avatar Jun 16 '22 14:06 bgavrilMS

The only dependencies I see are:

<PackageReference Include="System.Security.SecureString" Version="4.3.0" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.4.0" PrivateAssets="All" />

(not sure why we depdend on SecureString, I think it needs to go)

This should be good then, thank you! I was mentioning this because of the changes that would be required for the appdelegate, but those are likely to be documentation changes.

jeromelaban avatar Jun 16 '22 14:06 jeromelaban

@bgavrilMS Is it working in iOS by using the MauiBuilder extension method as recommended by the MAUI team. Screenshot 2022-06-22 at 4 49 11 PM

joker109 avatar Jun 22 '22 11:06 joker109

This comment is a follow-up to changes I observed after upgrading the package to 4.45 for my net6-ios application (non-MAUI).

I used to have a hard crash when I used 4.43 as described in the issue 3272.

Now I get a surprising exception related to the redirect URI parameter:

MSAL.NetCore.4.45.0.0.MsalClientException: 
	ErrorCode: loopback_redirect_uri
Microsoft.Identity.Client.MsalClientException: Only loopback redirect uri is supported, but **msal<app_id>//auth/** was found. Configure http://localhost or http://localhost:port both during app registration and when you create the PublicClientApplication object. See https://aka.ms/msal-net-os-browser for details
   at Microsoft.Identity.Client.Platforms.Shared.Desktop.OsBrowser.DefaultOsBrowserWebUi.UpdateRedirectUri(Uri )
   at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceInternalAsync(IWebUI , CancellationToken )
   at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceVerifierAsync(CancellationToken )
   at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.GetTokenResponseAsync(CancellationToken )
   at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.ExecuteAsync(CancellationToken )
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken )
   at Microsoft.Identity.Client.ApiConfig.Executors.PublicClientExecutor.ExecuteAsync(AcquireTokenCommonParameters , AcquireTokenInteractiveParameters , CancellationToken )

Since I am using Azure B2C, I can't use localhost as it is not supported.

But, what makes this error even more suspicious is that the static class AuthenticationContinuationHelper can't be found even though the Microsoft.Identity.Client NuGet package is referenced:

Screen Shot 2022-06-26 at 9 17 40 AM

With the current state of things related to the issue and the changes made, is that expected?

And to make it clear like others did, I am not using MAUI. It is a xamarin.ios application that been migrated to .net6-ios :)

kzryzstof avatar Jun 26 '22 13:06 kzryzstof