14 thoughts on “AAD Login on HoloLens 2

  1. Hi Pete,

    First of all thanks for this awesome tutorial, this is a topic rarely covered properly and you have done it very clearly.
    Could you please do a tutorial on using MSAL with Unity iOS or Android app?
    I have used both Amazon SDK and Firebase which integrate with AR/VR apps very easily.
    I don’t understand why Microsoft doesn’t provide the same level of flexibility in the MR space.

    1. I agree, and I think a sample/tutorial showing a VR/AR app accessing Azure services across platforms; iOS/Android/Windows MR/HoloLens/Windows Desktop would be really useful. If I get chance (I don’t think I will unfortunately) but would like to extend this sample (or a better scenario) to include those platforms and maybe discuss design decisions across those platforms. I wonder if the Azure Spatial Anchors samples might help as they are x-plat https://github.com/Azure/azure-spatial-anchors-samples.

  2. HI Pete, thank you for the detailed explanations on your tutorial.
    It helped me get through all the steps of deploying your sample app to HL2.

    I got an issue though when attempting AD authentication using MSAL.
    The app fails to show the interactive login dialog, and shows these errors instead (displayed on the main panel + UnityPlayer.log):

    [1]
    An error occurred while sending the request
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    AuthManager:Log(String, Boolean)
    System.Threading.ThreadStart:Invoke()
    d__4:MoveNext()
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
    System.Threading.ThreadStart:Invoke()
    UnityMainThreadDispatcher:Update()

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

    [2]
    Object reference not set to an instance of an object.
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    AuthManager:Log(String, Boolean)
    System.Threading.ThreadStart:Invoke()
    d__4:MoveNext()
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
    System.Threading.ThreadStart:Invoke()
    UnityMainThreadDispatcher:Update()

    I contacted MS Support, they asked to upgrade MSAL from 4.9.0 to 4.29.0, which I did and I also tried other things like changing platform settings (under inspector / plugin). Did you run into these same issues?

    1. Hi Houssam,

      I don’t recall seeing similar issues, are you using the same MSAL version that I used in my sample? I just tried an old build of that sample with the latest insider OS and I see the dialog as expected.

      Could you find the full unity log from your HoloLens device and send to my email address in the about page of this blog?
      You can find the log using the HoloLens developer portal File Explorer with the path:

      User Folders\LocalAppData\\TempState\UnityPlayer.log
      (Terminate the app if it is running otherwise the log file won’t get flushed to disk).

      Pete

      1. I am using the same MSAL version that’s in your sample, which is 4.9.0.
        It is worth noting that MS Support asked me to upgrade it to 4.27+ because of a known issue in MSAL prior to 4.27. So I updated the MSAL under Plugins/MSAL/Placeholder to 4.29.0 and updated the platform settings to match your sample’s (Editor / Any CPU / Any OS). And I removed the one under Plugins/MSAL. Redeployed to HL2 and got the same exception.
        I will send the log shortly.
        Regards
        Houssam

  3. Hey! I’m till trying to get this working on my own project. Everything works in the editor, but when built to the device, Device Code Flow fails at the callback point with no error or exception thrown. (We’ve talked in the slack about it.)

    I went through several cycles of excluding everything I could from the code stripper as discussed above with no success in UWP (although that made the difference in a standalone build).

    Now I’m wondering about the two versions of the microsoft.identity.client you have in this project. What’s the difference and could that be causing my issue?
    Thanks

  4. Hi Pete,
    Great article. Thank you.
    When I try the example code in the github and test the WAM using Iris toggle on. When click Sign in => I don’t see the Credential Dialogue window show up? It stuck there and show these logs in the windows:
    Logging in with WebAuthenticationCoreManager…

    I did check Hololens Sign-in options in the settings and see it is as the picture shown in the article?
    Am I missing anything?

  5. Thanks for this article, I was referred to it by someone on the Hololens Developer group on facebook. I am trying to get authentication working such that users do not need to login again to get access to an internal web API so I am hoping that I find the solution here. I have hit a problem though with the WAM login provider. The app appears to hang on the following line in the WAMLoginProvider.

    var consentResult = await Windows.Security.Credentials.UI.UserConsentVerifier.RequestVerificationAsync(“Please verify your credentials”);

    In the device portal I can see that Credential Dialog process/app appears but I do not see anything in the device display. Has anyone else come across this problem?

    I am using Iris authentication on the device.

    1. Hi Phil,

      Yes, this has been noted in an earlier comment. I haven’t had chance to fully investigate this but here is one observation I have made that might help. I had a build of the sample that I used previously for testing deployed to a HoloLens 2. I opened that app and tried to auth using the WindowsAuthenticationManager and I saw the same behaviour that you mentioned. The call to UserConsentVerifier.CheckAvailabilityAsync() didn’t result in the dialog being shown – it just silently failed somehow. When I checked the HoloLens privacy settings I noticed that the Eye Tracker capability was not switched on. I switched it on and I could invoke the dialog again.

        1. Hi Phil,

          See my other answer here referring to
          UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
          {), false);

        1. Hi Tom,

          I have replicated this issue and I believe the fix is to schedule the code that triggers the dialog to run on the UI thread. Something like:

          UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
          {
          // code here…
          }, false);

          I’m not sure what changed as this worked in an earlier unity build but I will update the repo with this fix within the next week.

          1. Thanks Pete, think that indeed solves it. By now we actually managed to get the access token in Unity. So that’s great. Thanks.

Leave a Reply to tle Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.