适用于Windows Phone 8.1的ADAL问题

时间:2015-02-07 00:00:04

标签: c# azure windows-phone-8.1 adal

我正在创建一个需要针对Azure Active Directory OAuth端点进行身份验证的Windows Phone 8.1应用程序(Windows运行时)。我正在使用ADAL for WP81 nuget包作为身份验证管理器来获取OAuth令牌。

我正在努力解决的问题是,我需要在电话页面生命周期中调用各种ADAL登录方法。现在我正在AuthenticationContext.AquireTokenAndContine()事件中调用Page.Loaded。我还实现了github示例代码中描述的ContinuationManagerIWebAuthenticationContinuableApp.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);
         }
    }

1 个答案:

答案 0 :(得分:1)

ADAL使用WebAUthenticationBroker(WAB)显示其提示。 Windows Phone 8.1中的WAB在加载应用程序的整个UX之前不会显示,因此您当前的方法位置将不起作用 - 至少在WAB行为未更改之前。有关类似的主题,请参阅Authentication failed with Azure Active Directory in Windows Phone