:通过IdentityServer3通过LDAPvalidation用户
我需要一种方法来通过IdentityServer3validation组织内的用户(使用LDAP和Active Directory)并授予他们对资源的访问权限。
IdentityServer3似乎是OpenID Connect协议的实现框架,适用于身份validation和授权。
到目前为止,我已经能够使用InMemory实现validation硬编码用户并获得JWT(JSON Web令牌)访问令牌。
请参考这个例子:
https://rajdeep.io/2015/05/07/creating-a-single-sign-on-using-thinktecture-identity-server-part-1/
但是,在我必须validation大型组织中的用户(存储在活动目录中)并发出令牌来访问资源的情况下,这不会非常有用。
以下是我根据此链接所做的工作
( http://stackoverflow.com/questions/31536420/thinktecture-identityserver-v3-with-windowsauth
):
-
创建了一个实现IUserService的ActiveDirectoryUserService。
namespace LDAPSSO { public class ActiveDirectoryUserService : IUserService { private const string DOMAIN = "company domain"; public Task AuthenticateExternalAsync(ExternalIdentity externalUser, SignInMessage message) { return Task.FromResult(null); } public Task AuthenticateLocalAsync(string username, string password, SignInMessage message) { try { using (var pc = new PrincipalContext(ContextType.Domain, DOMAIN)) { if (pc.ValidateCredentials(username, password)) { using (var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, username)) { if (user != null) { return Task.FromResult(new AuthenticateResult(subject: Guid.NewGuid().ToString(), name: username)); } } } // The user name or password is incorrect return Task.FromResult(null); } } catch { // Server error return Task.FromResult(null); } } } }
参考: “ https://gist.github.com/tjrobinson/0ad6c790e90d7a385eb1 ”
- 创建了一个实现IClientStore的MyClientStore
- 创建了一个实现IScopeStore的MyScopeStore
-
将此注册到工厂如下:
public class Factory { public static IdentityServerServiceFactory Configure() { var factory = new IdentityServerServiceFactory { UserService = new Registration(), // Don't need, but mandatory for idsvr3 ClientStore = new Registration(), ScopeStore = new Registration() }; return factory; }
即使我有这个工作,是否需要通过身份服务器提供的登录表单与用户输入的凭据进行比较? (请看下图):
授权服务器登录
为了从IdentityServer3登录页面提取用户凭据并针对Active Directoryvalidation,我需要做些什么?
这是正确的方法吗? 请建议。
投入和建议表示赞赏。
先感谢您!
我将实现Active Directory作为外部身份提供者 。
这样您就不必维护任何自定义代码,并且如果您被锁定,则继续使用AD的LDAPfunction。 您可以通过禁用Identity Server中的本地登录或使用acr_values
的idp
值或甚至基于每个客户端来使其成为唯一的身份提供者。