Ошибка аутентификации Azure Active Directory Unity - PullRequest
0 голосов
/ 12 марта 2019

Я пытаюсь внедрить аутентификацию Azure AD в мое приложение Unity.Я начал с кода и документации отсюда: 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 error 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.

Есть идеи?

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...