我正在创建一个需要针对 Azure Active Directory OAuth 端点进行身份验证的 Windows Phone 8.1 应用程序(Windows 运行时)。我使用 ADAL for WP81 nuget 包作为身份验证管理器来获取 OAuth 令牌。
我正在努力解决的问题是我需要在电话页面生命周期中调用各种 ADAL 登录方法。现在我正在AuthenticationContext.AquireTokenAndContine()
参加Page.Loaded
活动。我还按照 github 示例代码中的描述实现了ContinuationManager
、IWebAuthenticationContinuable
和事件。App.Activated
我也Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri()
用来获取我的客户端 URI。
无论我做什么,我都会继续收到以下错误。关于我能做什么的任何见解?预先感谢您的帮助。
“Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException”发生在 mscorlib.ni.dll 中,但未在用户代码中处理
附加信息: authentication_ui_failed:基于浏览器的身份验证对话框未能完成
async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
await LoadFromViewModel();
}
public async Task LoadFromViewModel()
{
// Try to get a token without triggering any user prompt.
// ADAL will check whether the requested token is in the cache or can be obtained without user itneraction (e.g. via a refresh token).
AuthenticationResult result = await authContext.AcquireTokenSilentAsync(this.viewModel.RESTApiResourceUri, this.viewModel.AzureADClientId);
if (result != null && result.Status == AuthenticationStatus.Success)
{
// A token was successfully retrieved. Get the To Do list for the current user
await viewModel.BindData();
}
else
{
// Acquiring a token without user interaction was not possible.
// Trigger an authentication experience and specify that once a token has been obtained the GetTodoList method should be called
authContext.AcquireTokenAndContinue(this.viewModel.RESTApiResourceUri, this.viewModel.AzureADClientId, this.viewModel.AzureADRedirectUri, AuthenticationSuceeded);
}
}