Authenticate and GetRoles of ActiveDirectory users in a disconnected WPF application via MembershipProvider

StackOverflow https://stackoverflow.com/questions/324752

Question

I have a project requirement where I need to authenticate against ActiveDirectory in a remote/disconnected WPF application.

There is probably several ways to attempt to do this, but what would be the best approach using ActiveDirectory's MembershipProvider?

I need to:

  1. Authenticate that the user exists.
  2. obtain the AD user's groups and roles.

This needs to happen from a remote location, outside of the network Active Directory resides on.

Was it helpful?

Solution

From within a WinForms or WPF application you can now take advantage of "Client Application Services" (thanks MS for a very generic name, searching for help is now very painful!).

This allows you to connect to a WCF service that can validate the logins. The link above has a walkthrough that shows how easy it is to get it all working, once you have a working app you can modify your config to point to a different MembershipProvider and/or RoleProvider.

It's worth noting that the out-of-the-box solution includes a MembershipProvider named ActiveDirectoryMembershipProvider, but there's no RoleProvider for Active Directory.

If you do require the ability to get Roles (or Groups) and you are working with .NET 4.0 then you can take advantage of the new Active Directory API added that makes everything much easier, namely System.DirectoryServices.AccountManagement. For the most basic of Membership and Role services you'll want to have the following to create your own basic MembershipProvider and RoleProvider:

You can implement as little or as much of the API as needed, you should find everything you need in the new AccountManagement namespace to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top