C# Azure Active Directory授权

C# Azure Active Directory授权,c#,.net,azure,authorization,azure-active-directory,C#,.net,Azure,Authorization,Azure Active Directory,我正在尝试通过azure应用程序中的AAD和自己的客户端进行用户授权。我的AAD中有一个名为“user”的用户,密码为“pass”。当用户尝试连接应用程序时: try { if (false == Utils.DataBaseUtils.CheckLoginCorrect(sceneMessage.Login, sceneMessage.Pwd)) {

我正在尝试通过azure应用程序中的AAD和自己的客户端进行用户授权。我的AAD中有一个名为“user”的用户,密码为“pass”。当用户尝试连接应用程序时:

            try
            {
                if (false == Utils.DataBaseUtils.CheckLoginCorrect(sceneMessage.Login, sceneMessage.Pwd))
                {
                    WriteToLog("Wrong password");
                    SendError(handler, "Wrong password");
                    return;
                }
            }
            catch (Exception e)
            {
                WriteToLog("Unexpected problem when checking password: "+e.ToString());
                SendError(handler, "Unexpected problem when checking password");
                return;
            }

    //authorization using Azure Active Directory
    public static bool CheckLoginCorrect(string login, string password)
    {
        if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))  //validatecredentials return true if log or pass is empty
            return false;

        using (PrincipalContext adContext = new PrincipalContext(ContextType.Domain, "mydomain156.onmicrosoft.com"))  //represent AD
        {
            return adContext.ValidateCredentials(login, password, ContextOptions.Negotiate);
        }
    }
其中
sceneMessage.Login==“User”
sceneMessage.Pwd==“pass”
。 这里我得到了一个错误:

System.DirectoryServices.AccountManagement.PrincipalServerDownException: 无法联系服务器。--> System.DirectoryServices.Protocols.LdapException:LDAP服务器是 不可用


有人能帮忙吗?

看起来您正在使用传统本地广告的广告库。要针对Azure广告进行编程,请使用Auzre身份验证库(AAL)。注意,上周AAL被重命名为Active Directory身份验证库


Azure Active Directory身份验证库(ADAL,前身为AAL)是用于在Azure Active Directory中验证用户的正确API。版本1已发布,您可以在此处找到更多信息: