Leaf
Leaf

Reputation: 553

Azure Active Directory authorization

I'm trying to do user authorization though AAD in azure app with own client side. I have a user named "User" in my AAD with password "pass". When user is trying to connect the app:

            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);
        }
    }

Where sceneMessage.Login == "User", sceneMessage.Pwd == "pass". Here I'm getting error:

System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted. ---> System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.

Could anybody help, please?

Upvotes: 2

Views: 3188

Answers (2)

Rich Randall
Rich Randall

Reputation: 1982

Azure Active Directory Authentication Library (ADAL, formerly AAL) is the correct API to use for authenticating users in Azure Active Directory. Version 1 has been released and you can find more information here:

http://www.cloudidentity.com/blog/2013/09/12/active-directory-authentication-library-adal-v1-for-net-general-availability/

Upvotes: 0

Rick Rainey
Rick Rainey

Reputation: 11256

It looks like you're using the AD libraries for traditional on-premise AD. To program against Azure AD, use the Auzre Authentication Library (AAL). Note, last week AAL was renamed to Active Directory Authentication Library.

http://msdn.microsoft.com/en-us/library/jj573266.aspx

Upvotes: 1

Related Questions