-
Notifications
You must be signed in to change notification settings - Fork 345
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
[Bug] HoloLens 2 device code flow does not work #2231
Comments
Hi @rfurmaniak - when you say that the platform is "Unity 2019.4.0f1, UWP, IL2CPP, ARM for HoloLens 2", how does this resolve to a platform supported by MSAL? https://www.nuget.org/packages/Microsoft.Identity.Client/ Do you target the .netstandard version of MSAL? Or the UWP version? The root cause is pretty clear - the json serialization fails. This is because it's probably using reflection in an environment where reflection is not possible. As far as I know, if you try to use the .NETStanadard1.3 version of MSAL, we will use a version of Newtonsoft.Json that does not use reflection - https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/Newtonsoft.Json.csproj |
Hi @bgavrilMS, thanks for quick response. |
Hi @bgavrilMS, We have created a test app registration, just so you can use it to reproduce this issue. I hope this helps and brings more information. |
@jmprieur - is this something for our friends in CXP to engage with again? |
Can you reproduce this issue on the HoloLens 2 emulator? If so, what steps do you take to verify the issue using the emulator? |
We've never really been using the emulator, as it is unreliable for us for testing, due to it being x86 platform and not ARM. But I will try to deploy it on the emulator and let you know as soon as I have results. |
I managed to deploy the solution I've sent previously to emulator. The issue can be reproduced there, all there is to do is to deploy the app and run it in the emulator. After the startup, error appears in log and message about not being able to login is displayed on the screen. |
Thanks and can you please share the steps as well as screen to reproduce for emulator. Please share in the google drive. |
I think I am reproducing the issue on the HoloLens 2 emulator FWIW. It might be an issue with the code running in Unity's IL2CPP runtime. I've attached the full output log from VS when running the app on the emulator in case it helps. This doesn't appear to be working on the emulator/device. _authResult = await _identityClient.AcquireTokenWithDeviceCode(_authScopes,
deviceCodeResultCallback).ExecuteAsync(cancellationToken); Snippet from the log (note, the message is user defined):
|
Thanks John and its also verified working with Unity editor of Microsoft.Identity.client.dll (latest netstandard 1.3 dll). However issue of AcquireTokenWithDeviceCode method when deployed to Hololens emulator using Visual Studio. |
Update after synching with Jitendra from CPX.
this answers some question. The platform is CoreCLR |
MSAL code has this TenantDiscoveryEndPoint property and it is crashing while working on Hololens emulator or Device. |
@jitendraRai |
I've found a work around for this issue. The clue was in Unity Issue Tracker - [IL2CPP] NotSupportedExceptions exception is thrown in build with Newtonsoft.Json plugin (unity3d.com). I needed to add to link.xml: <assembly fullname="System" preserve="all" />
<assembly fullname="System.Core" preserve="all" /> Additionally and what the Unity docs are inaccurate about is that this must be in the root Assets/link.xml. Lower or package link.xml inclusions don't work. |
Thank you @najadojo! The solution you posted is working :) |
Thanks @najadojo for the workaround, and @rfurmaniak for confirming. Added an entry in the wiki: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/hololens2 |
@jmprieur This isn't a HL2 specific issue it is a general Unity IL2CPP issue. I'd suggest that you title the wiki entry to include that fact so more folks can find the solution. |
Thanks for the update, @najadojo |
As already been mentioned, the issue comes from Unity IL2CPP. When optimizing code (using code stripping), it removes needed dependencies for reflection to work (because it can't properly detect that usage). We investigated removing reflection related code from MSAL but it proved to be very impractical. Unity themselves have this documented in their docs Managed code stripping and recommend to use Link XML method as one of the solutions to this issue. This is our recommendation as well. |
Logs and Network traces
Error setting value to 'TenantDiscoveryEndpoint' on 'Microsoft.Identity.Client.Instance.Discovery.InstanceDiscoveryResponse'. at Microsoft.Identity.Json.Serialization.ExpressionValueProvider.SetValue (System.Object target, System.Object value) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Microsoft.Identity.Json.Serialization.JsonProperty property, Microsoft.Identity.Json.JsonConverter propertyConverter, Microsoft.Identity.Json.Serialization.JsonContainerContract containerContract, Microsoft.Identity.Json.Serialization.JsonProperty containerProperty, Microsoft.Identity.Json.JsonReader reader, System.Object target) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Microsoft.Identity.Json.JsonReader reader, Microsoft.Identity.Json.Serialization.JsonObjectContract contract, Microsoft.Identity.Json.Serialization.JsonProperty member, System.String id) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.Serialization.JsonSerializerInternalReader.CreateObject (Microsoft.Identity.Json.JsonReader reader, System.Type objectType, Microsoft.Identity.Json.Serialization.JsonContract contract, Microsoft.Identity.Json.Serialization.JsonProperty member, Microsoft.Identity.Json.Serialization.JsonContainerContract containerContract, Microsoft.Identity.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Microsoft.Identity.Json.JsonReader reader, System.Type objectType, Microsoft.Identity.Json.Serialization.JsonContract contract, Microsoft.Identity.Json.Serialization.JsonProperty member, Microsoft.Identity.Json.Serialization.JsonContainerContract containerContract, Microsoft.Identity.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.Serialization.JsonSerializerInternalReader.Deserialize (Microsoft.Identity.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.JsonSerializer.DeserializeInternal (Microsoft.Identity.Json.JsonReader reader, System.Type objectType) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Microsoft.Identity.Json.JsonSerializerSettings settings) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.JsonConvert.DeserializeObject[T] (System.String value, Microsoft.Identity.Json.JsonSerializerSettings settings) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Client.Utils.JsonHelper.DeserializeFromJson[T] (System.String json) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Client.OAuth2.OAuth2Client.CreateResponse[T] (Microsoft.Identity.Client.Http.HttpResponse response, Microsoft.Identity.Client.Internal.RequestContext requestContext) [0x00000] in <00000000000000000000000000000000>:0 \r\n at Microsoft.Identity.Json.Linq.Extensions+<Convert>d__14
2[T,U].<>m__Finally1 () [0x00000] in <00000000000000000000000000000000>:0 \r\n at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000]`Which Version of MSAL are you using ?
4.22, built from the current MSAL master branch.
Platform
Unity 2019.4.0f1, UWP, IL2CPP, ARM for HoloLens 2
What authentication flow has the issue?
Other? - please describe;
Is this a new or existing app?
We were using some version of MSAL v3, but application in production started having issues with authenticating private accounts. After long support session we learned that we should change a little our flow, this required update to MSAL v4.
Unfortunately, while everything works fine in the editor, version deployed on the HoloLens does not.
Repro
I am attaching whole script that contains our logic for device code.
Controller script only calls SignInWithDeviceFlow() method and this method fails on AcquireToken.
DeviceCodeAuthenticator.txt
Expected behavior
Using AcquireTokenWithDeviceCode should give code to authenticate user.
Actual behavior
Exception is being thrown and no code is given.
Possible Solution
This issue appeared in MSAL v3 we were using previously and link.xml fixed it. In the new version of MSAL, this fix does not work.
I have turned panic mode on and basically put all possible options in link.xml, still does not work. Here is the content:
Additional context/ Logs / Screenshots
I have tried to cheat Unity bytestripping, by pasting the library into the build directory and then deploying it to the HoloLens, but it changes nothing.
I have tried using several versions of MSAL:
The text was updated successfully, but these errors were encountered: