3
votes

I am developing an Unity app for tablets in which our employees calendar info is collected from Microsoft Graph and shown on screen. But I'm having problems with logging in users to MS Graph without being redirected to using a web browser.

Currently I am connecting to our app's server endpoint through https://login.microsoftonline.com/tenant_id_here/oauth2/token , but I can't find a working way to login for a user, which is nessesary to ask for the calendar info.

The grant_type password from Flow 2 in this blog is supposed to do exactly this: http://codematters.tech/getting-access-token-for-microsoft-graph-using-oauth-rest-api/ However, using the grant_type password will always return an errorcode, even when the username & password is correct:

AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password

After searching answers, it appears that grant_type password has been put out of use: https://github.com/microsoftgraph/microsoft-graph-docs/issues/2657#issuecomment-390036447

If this is the case, how am I supposed to get a token for a user using username and password?

Now, I have indeed found a MS Graph SDK (https://github.com/microsoftgraph/msgraph-sdk-dotnet) which might solve this problem, but sadly it is running on a later version .NET that Unity does not support.

For reference, the app I'm trying to create will have a simple workflow like this:

User logs in through app and gets token > App asks Office365 for user calendar info using token > App displays calendar info, and refreshes token

Does anybody have an idea on how to do this?

1
Hi, when you say that the SDK runs on a later version of .NET that Unity does not support have to tried building your Unity project using IL2CPP instead of the .NET scripting backend? I believe that it exposes a larger .NET surface and may support later versions of .NETslaphshot33324
Why can't you you use the browser to authenticate the user when using Unity?Michael Mainer
@MichaelMainer Although I guess its certainly possible to open up a browser from Unity and send my token request through there, it would be out-of-process and tricky to get the response back into Unity. Not to mention detecting if the user enters the wrong login info. Regardless, this is my plan B.NicolasZ
@slaphshot33324 Thanks for suggesting IL2CPP! It managed to solve a few missing namespaces and complile successfully, but I am still getting exceptions from deep within those namespaces, so I will have to research that to see if the cause is something I can fix.NicolasZ

1 Answers

1
votes

According to your description, I assume you want to logging into Microsoft Graph with username and password using Unity.

There are many way to get the accesstoken to connect the Microsoft Graph.

Base on your description, we can use the REST API to authenticate the user.

For more information, we can refer to this document.