We develop a bunch of augmented reality applications for our company. The applications are based on the game engine Unity (currently in the version 2020.3.7f1). Now, we're facing the point that we'd like to implement a SSO method in our apps, so every member of our company authenticates himself with his company user credentials. To authenticate the user we want to / have to use the Microsoft identity platform and thus the Microsoft Authentication Library (MSAL).
We already created an client on Azure with a client id, redirect uri, authority uri, endpoint, tenant, etc and it was tested successfully with an official sample project by Microsoft (https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-ios).
But now we stuck at the point to establish this process in Unity. We created the MSAL library dll (https://github.com/AzureAD/microsoft-authentication-library-for-dotnet), imported it into Unity and called it by using the namespace Microsoft.Identity.Client. Due to security reasons we're only allowed to use PublicClientApplicationBuilder (which makes totally sense) so we need the web based login screen. The problem is that we can't implement a web view in Unity where the user can sign in to Microsoft and we can parse the received token out of the web view into our app for further communications.
We did a lot of internet research to find a solution but there are only some posts about MSAL in Unity in combination with Android and other posts which reference to the git repos I mentioned before.
How can we use MSAL in Unity for iOS devices?
Example code:
IPublicClientApplication PublicClientApp = PublicClientApplicationBuilder
.Create(kClientID)
.WithRedirectUri(kRedirectUri)
.WithAuthority(new Uri(kAuthority))
.Build();
IEnumerable<string> scopes = new List<string> { "https://graph.microsoft.com/.default" };
AuthenticationResult result;
result = await PublicClientApp.AcquireTokenInteractive(scopes)
.ExecuteAsync();
result = await PublicClientApp
.AcquireTokenInteractive(scopes)
.WithParentActivityOrWindow(new object)
.ExecuteAsync();
Debug.Log(result.AccessToken);