【问题标题】:ADAL for Windows Phone 8.1 ProblemsWindows Phone 8.1 的 ADAL 问题
【发布时间】:2015-04-07 05:58:22
【问题描述】:

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

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

【问题讨论】:

  • 您在运行示例时是否遇到同样的错误?这可能是一个很好的起点。如果那里没有错误,您应该检查您在应用中的不同之处。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多