How to use Servicestack Authentication with Active Directory/Windows Authentication?

后端 未结 2 1556
感情败类
感情败类 2021-02-01 17:49

I am creating a secure (SSL) public service where the users credentials reside in Active Directory. I want to leverage ServiceStack\'s Authentication and have read over the wiki

2条回答
  •  花落未央
    2021-02-01 18:01

    Here is what Demis Bellot said on twitter. Probably possible but needs more research.

    Not something I've investigated, don't work in the Win/Active Directory anymore. Requires some R&D to find/resolve the issue

    I did eventually get a prototype service working with AD. I implemented the CredentialsAuthProvider. Now this is not tied to ASP.NET IWA at all, but does easily check to see if the user is in AD. Hopefully this might help someone.

    public class LDAPAuthProvider : CredentialsAuthProvider
    {
        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
                        {
                            //Check to see if the username/password combo is valid, an exception will be thrown if the username or password is wrong
                            try
                            {
                                DirectoryEntry entry = new DirectoryEntry(ConfigurationManager.AppSettings["TargetOU"], userName, password);
                                object nativeObject = entry.NativeObject;
                            }
                            catch (Exception)
                            {
                                //This means the username/password combo failed
                                return false;
                            }
    
                            return true;
                        }
    }
    

提交回复
热议问题