我在Win10 UWP应用中使用ADAL。这是一段代码:
// 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;
有时它会因以下错误而失败,而不会打开身份验证窗口:
authentication_ui_failed: The browser based authentication dialog failed to complete. Value does not fall within the expected range.
有时,它会启动auth窗口,但无法重定向,生成:
"authentication_ui_failed: The browser based authentication dialog failed to complete. The system cannot locate the resource specified. (Exception from HRESULT: 0x800C0005)"
这使用了该库的WinRT版本。使用.NET版本的类似代码在控制台应用程序中运行良好:
// .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;
答案 0 :(得分:2)
这通常是由商店和UWP应用程序的沙盒引起的。应用程序的重定向uri至少应与运行时指定的重定向uri相匹配 - 请参阅github.com/azuread上的windows store示例。其他可能影响行为的事情是盒子上的隐私设置,使用本地网络而不要求正确的功能..:适用于Windows应用商店应用的所有限制也将适用于ADAL的使用。 另外:我可以问你为什么要将自定义缓存传递给应用程序吗?对于像沙盒存储应用程序这样的沙盒环境中运行的应用程序而言,这种情况并不常见。