UWP + ADAL身份验证=异常 [英] UWP + ADAL authentication = exception

查看:110
本文介绍了UWP + ADAL身份验证=异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xamarin为所有三个平台(UWP,Android和iOS)开发移动应用程序,我们的后端运行AAD,以便通过移动应用程序验证用户我正在使用ADAL的预发布版本:

I'm developing a mobile application for all three platforms (UWP, Android, and iOS) using xamarin, our backend runs AAD so to authenticate a user through the mobile apps I'm using a prerelease version of ADAL:

Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory version 4.0.209160138-alpha

Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory version 4.0.209160138-alpha

有趣的是,代码在android上工作正常iOS但在Windows手机模拟器上会抛出异常:

The funny thing is that the code works fine on android and iOS but on a windows phone emulator it'll throw an exception:

authentication_ui_failed:基于浏览器的身份验证对话框无法完成。

内部异常:

System.IO.FileNotFoundException: The specified protocol is unknown. (Exception from HRESULT: 0x800C000D) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.WebUI.<AcquireAuthorizationAsync>d__0.MoveNext()

和stacktrace:

and stacktrace:

at Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.WebUI.<AcquireAuthorizationAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.<AcquireAuthorizationAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.AcquireTokenInteractiveHandler.<PreTokenRequest>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.<RunAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenCommonAsync>d__4e.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenAsync>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ThreeAndMore.Mobile.Services.NetworkManager.<Login>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ThreeAndMore.Mobile.Windows.MainPage.<Login>d__1.MoveNext()





和我正在使用的代码

And the code I'm using

        public async Task<AuthenticationResult> Login(IPlatformParameters parameters, bool isSignIn)
    {
        var authContext = new AuthenticationContext(AUTHORITY_URL, new TokenCache());

        if (CORRELATION_ID != null &&
                CORRELATION_ID.Trim().Length != 0)
        {
            authContext.CorrelationId = Guid.Parse(CORRELATION_ID);
        }

        String policy = "";
        if (isSignIn)
            policy = EMAIL_SIGNIN_POLICY;
        else
            policy = EMAIL_SIGNUP_POLICY;

        return await authContext.AcquireTokenAsync(SCOPES, ADDITIONAL_SCOPES, CLIENT_ID, new Uri(REDIRECT_URL), parameters, UserIdentifier.AnyUser, EXTRA_QP, policy);            
    }
}



这样被调用:

which gets called like this:

        private async void Login()
    {
        try
        {
            NetworkManager mngr = NetworkManager.GetInstance();
            AuthenticationResult result = await mngr.Login(new PlatformParameters(PromptBehavior.Auto, false), true);
            MessageDialog msgbox = new MessageDialog("welcome " + result.UserInfo.Name + "User:" + result.UserInfo.DisplayableId);
            await msgbox.ShowAsync();

        }
        catch (Exception e)
        {
            MessageDialog msgbox = new MessageDialog(String.Format("LOGIN EXCEPTION: {0} with hresult: {1} and inner exception {2} and stacktrace: {3}", e.Message, e.HResult, e.InnerException, e.StackTrace));
            await msgbox.ShowAsync();
            System.Diagnostics.Debug.WriteLine(String.Format("LOGIN EXCEPTION: {0} with hresult: {1} and inner exception {2} and stacktrace: {3}", e.Message, e.HResult, e.InnerException, e.StackTrace));
        }

    }

到底是怎么回事在这里?

What the hell is going on here?

推荐答案

Hello Thierry,

对于这个问题,我做了一些研究,发现它可能与
的沙箱环境有关  商店和UWP应用:
< span style ="font-weight:normal"> AcquireTokenAsync
在UWP应用程序中失败

For this issue, I did some research and found it could be related with the sandbox environment of  store and UWP apps:AcquireTokenAsync fails in a UWP app.

在做了一些研究后,似乎当前的稳定版本(2.18.206251556)可以工作使用UWP,请检查此链接

带有Windows Universal App的Active Directory身份验证库

After doing some more research, it seems the Current stable version (2.18.206251556) could work with UWP, check this link Active Directory Authentication Library with Windows Universal App.

问候。


这篇关于UWP + ADAL身份验证=异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆