AcquireTokenAsync fails in a UWP app

六月ゝ 毕业季﹏ 提交于 2019-12-11 19:33:27

问题


I'm using ADAL in my Win10 UWP app. Here is a snippet of code:

// WinRT, UWP app. Doesn't work
TokenCache TC = new TokenCache();
authContext = new AuthenticationContext(authority, true, TC);
var authresult = await authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri));
token = authresult.AccessToken;

Sometimes it fails with the following error, without ever bringing up the auth window:

authentication_ui_failed: The browser based authentication dialog failed to complete. Value does not fall within the expected range.

Occasionally, it does bring up the auth window but fails to redirect, producing:

"authentication_ui_failed: The browser based authentication dialog failed to complete. The system cannot locate the resource specified. (Exception from HRESULT: 0x800C0005)"

This uses a WinRT version of the library. A similar code using .NET version works great from the console app:

// .NET, console app. Works great
TokenCache TC = new TokenCache();
authContext = new AuthenticationContext(authority, TC);
var authresult = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri));
token = authresult.AccessToken;

回答1:


This is typically caused by the sandboxing of store and UWP apps. At a minimum, the redirect uri of the app should match the one assigned by the runtime - see the windows store sample on github.com/azuread. Other things that might impact the behavior are privacy settings on the box, use of local network without asking for the correct capabilities..: all the restrictions that apply to windows store apps will apply to the use of ADAL as well. Also: can I ask you why you are passing a custom cache to the app? That's not usual for apps running on sandboxes environments like the windows store apps.



来源:https://stackoverflow.com/questions/31755699/acquiretokenasync-fails-in-a-uwp-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!