HoloLens, msgraph, oauth2

Microsoft Graph Auth on HoloLens–Device Code Flow

device-code

I was working with a sample that I had previously written using the Microsoft Auth Library which was originally used as an example of delegated auth on HoloLens but I recently extended the sample to also show ‘device code flow’ which you can see in the OAuth 2.0 spec here https://oauth.net/2/grant-types/device-code/. This flow allows the auth to happen on a second device which may be more convenient if typing passwords or codes is required on a HoloLens device given that the keyboard uses a gaze + air-tap input mechanism.

The video shows the device code flow in action using a HoloLens and a mobile phone as the second device.

So, I select the ‘code flow’ option by gazing and air-tapping (voice commands are also available). The flow is initiated by a call to AcquireTokenWithDeviceCodeAsync which is a method on the PublicClientApplication type from the MSAL library.

The UI then shows a url and a code. On my phone (or other device) I navigate to the url in a browser and type in the code. I can then authenticate with my work account credentials and a token is returned to my app so I can use that in a call to the Microsoft Graph API to retrieve emails which I then display when clicking on the envelope models on the left.

The repo for this sample can be found here

Tagged , ,

4 thoughts on “Microsoft Graph Auth on HoloLens–Device Code Flow

  1. Hey Pete,

    I’m receiving an exception while trying to request for a token using AcquireTokenWithDeviceCode method – “The method or operation is not implemented.”

    This is the link to my code – https://pastebin.com/H5Yzvdmz

    Line 100 – Exception is thrown from
    Line 128 – Exception is caught

    1. This is an issue in v4.16.1.0 of MSAL running in the Unity editor as the library calls System.Net.ServicePoint.set_ConnectionLeaseTimeout which doesn’t appear to be implemented in recent versions of mono for unity. I can confirm that v4.9.0.0 works in this scenario.

Leave a 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.