Converged applicationsand click on
Add an app. Choose a name and select
Native Applicationon the next screen.
Microsoft Graph Permissionsadd some
Delegated Permissions. I'm going to access the OneDrive in part two, hence I'm adding
Files.ReadWrite.Allto the existing
Action<string>callback. I wouldn't normally do this in LoB application development where I can use IoC to inject the logging framework of my choice on instantiation. In Unity, ctor injection isn't really a thing. The logging callback seems to be the most clean and obvious approach to me for this sample.
Microsoft.Identity.Clientas new NuGet dependency to the library project (it's still in beta, so enable previews). Although the MSAL brings its own key management, I use the
Windows.Security.Credentials.PasswordVaultfor storing UserId and AccessToken. This is to avoid leaking the MSAL dependency into any msgraph component. Storing the token in
ApplicationData.Current.LocalSettingsis not considered safe. Have a look at my
CredentialServiceclass, if you're interested. More on the credential locker here .
Initmethod that takes the Application Id as parameter.
AcquireTokenAsync. To avoid going through the OID flow every time the login button is pressed, I try to acquire the token silently from the token store first. If that is failing, an
MsalUiRequiredExceptionis thrown and a browser view is opened for the manual login.
RectangleButtons and an
UITextto the scene, they can be found in the UX prefabs folder of the MRTK. I will use them to start the login flow and display the log result. After renaming and positioning the elements accordingly, my scene now contains the following elements:
IInputClickHandlerof the buttons will go into the Scripts folders.
MsGraph.Library.Placeholdersolution to the sample code, but it's just an stub project. The MSAL library doesn't need a placeholder plugin, as my UWP library encapsulates that dependency.
ApplicationIdproperty to the Unity Editor. This is the place to put in the application id from the app registration portal. My authentication service implementation is instantiated and initialized in the
Startmethod, the actual call to start the login only happens on click. Since I'm targeting the .NET 4.6 Api Compat Level, I can happily use async & await.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.