在Active Directory身份验证库2.6.1-alpha中找不到ActiveDirectoryAuthenticationException

时间:2014-05-07 16:08:49

标签: c# exception azure active-directory azure-active-directory

当我尝试在 Active Directory身份验证库2.6.1-alpha 中使用ActiveDirectoryAuthenticationException时,无法找到它。 (然而,它存在于1.0.3中)。

我可以使用什么来检测失败的身份验证?

1.0.3代码:

try
{
    result = authContext.AcquireToken(todoListResourceId, clientId, redirectUri, PromptBehavior.Never);

    // A valid token is in the cache - get the To Do list.
    SignInButton.Content = "Clear Cache";
    GetTodoList();
}
catch (ActiveDirectoryAuthenticationException ex)
{
    if (ex.ErrorCode == "user_interaction_required")
    {
        // There are no tokens in the cache.  Proceed without calling the To Do list service.
    }
    else
    {
        // An unexpected error occurred.
        string message = ex.Message;
        if (ex.InnerException != null)
        {
            message += "Inner Exception : " + ex.InnerException.Message;
        }
        MessageBox.Show(message);
    }
    return;
}

2.6.1-alpha代码:

try
{
    result = await authContext.AcquireTokenAsync(todoListResourceId, clientId, redirectUri, PromptBehavior.Auto);

    // A valid token is in the cache - get the To Do list.
    return true;
}
catch (ActiveDirectoryAuthenticationException ex) // What to use here?
{
    if (ex.ErrorCode == "user_interaction_required")
    {
        // There are no tokens in the cache.  Proceed without calling the To Do list service.
    }
    else
    {
        // An unexpected error occurred.
        string message = ex.Message;
        if (ex.InnerException != null)
        {
            message += "Inner Exception : " + ex.InnerException.Message;
        }
        MessageBox.Show(message);
    }
}

return false;
}

1 个答案:

答案 0 :(得分:1)

您是否在Windows应用商店应用中使用该库?该版本的库(即ADAL WinRT)不会将ActiveDirectoryAuthenticationException公开为公共类型,因为ADAL WinRT从不抛出异常。它在AuthenticationResult中返回错误。

如果在.NET应用程序中使用ADAL 2.6.1-alpha,则可以找到异常类型。