azureauthenticationazure-active-directoryprincipalcontext

Azure Authentication with PrincipalContext - Server could not be contacted


So I'm trying to authenticate users that log into our website by running their credentials through windows/Azure authentication. It seems like the simplest way is to use the PrincipalContext class to conenct to the authentication endpoints. Code is super simple:

PrincipalContext pc = new PrincipalContext(ContextType.Domain, "<ourdomain>.com");
bool valid = pc.ValidateCredentials(user, pass);

I retrieved the domain by logging into Azure -> Active Directory -> Custom Domain Names ->

enter image description here

I used that value verbatim for the second PrincipalContext constructor argument above ^.

When I hit that bit of code, I am met with this error:

enter image description here

What am I doing wrong here? As far as I can tell the code should be pretty simple. Am I providing the wrong value for domain name? Is there any setup I'm missing? I'm finding all sorts of solutions/tutorials for Azure authentication but I don't know which ones to pursue. Any Help identifying the issue would be greatly appreciated.

Thanks!


Solution

  • Azure AD and Windows Server AD are not the same thing. They both aim to solve the same problems but in different manner. You are trying PrincipalContext which is for Windows Server AD.

    You can find complete documentation on Azure active directory.

    Please go through the Identity samples which help you to achieve authentication.