Azure Active Directory Unity身份验证错误

时间:2019-03-12 14:33:16

标签: unity3d authentication azure-active-directory

我正在尝试在我的Unity应用程序中实现Azure AD身份验证。我已经从这里的代码和文档开始:https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-windows-desktop。他们的Visual Studio示例项目工作正常,但是当我尝试在Unity项目中使用此代码时,尝试运行它时将失败。

string[] scopes = new string[] { "user.read" };     
public static string ClientId = {...} // my azure app id
private static string Tenant = {...} // my tenant id

private async void AsyncLoginButton()
    {
        AuthenticationResult authResult = null;

        string authority = "https://login.microsoftonline.com/" + Tenant;
        var app = new PublicClientApplication(ClientId, authority, TokenCacheHelper.GetUserCache());

        {...}

            try
            {
                authResult = await app.AcquireTokenAsync(scopes);                 
            }
            catch (MsalException msalex)
            {
                textContent.text = $"Error Acquiring Token:{msalex}";
                Debug.Log(msalex);
            }         

        {...}
    }

,出现以下错误-“无法注册窗口类,win32错误0”:

enter image description here

在上面的窗口中按OK后,它仅在AcquireTokenAsync的行中提供空引用。

NullReferenceException: Object reference not set to an instance of an object
Microsoft.Identity.Client.Platforms.net45.WebUI+<AcquireAuthorizationAsync>d__16.MoveNext () (at <a854dd38cefc420d850373110dec4a99>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+<AcquireAuthorizationAsync>d__10.MoveNext () (at <a854dd38cefc420d850373110dec4a99>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+<ExecuteAsync>d__9.MoveNext () (at <a854dd38cefc420d850373110dec4a99>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Microsoft.Identity.Client.Internal.Requests.RequestBase+<RunAsync>d__16.MoveNext () (at <a854dd38cefc420d850373110dec4a99>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Microsoft.Identity.Client.PublicClientApplication+<AcquireTokenForLoginHintCommonAsync>d__22.MoveNext () (at <a854dd38cefc420d850373110dec4a99>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Microsoft.Identity.Client.PublicClientApplication+<AcquireTokenAsync>d__5.MoveNext () (at <a854dd38cefc420d850373110dec4a99>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
ApplioMGE.Login+<AsyncLoginButton>d__37.MoveNext () (at Assets/Scripts/Transitional/Login.cs:136)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:111)
UnityEngine.UnitySynchronizationContext.Exec () (at C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:72)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at C:/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:93)

我认为这是在代码尝试弹出要求您提供凭据的Microsoft Graph API窗口时发生的,但是由于某些原因,这在Unity中不起作用。

有什么想法吗?

谢谢。

0 个答案:

没有答案