我需要一种方法通过 IdentityServer3 验证组织内的用户(使用 LDAP 和 Active Directory)并授予他们对资源的访问权限。
IdentityServer3 似乎是 OpenID Connect 协议(protocol)的实现框架,适用于身份验证和授权。
到目前为止,我已经能够使用 InMemory 实现验证硬编码用户并获取 JWT(JSON Web token )访问 token 。
请引用这个例子:
https://rajdeep.io/2015/05/07/creating-a-single-sign-on-using-thinktecture-identity-server-part-1/
但是,这在我的场景中并不是很有用,因为我必须验证大型组织中的用户(存储在事件目录中)并向他们颁发 token 以访问资源。
这是我根据此链接所做的事情
(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<AuthenticateResult> AuthenticateExternalAsync(ExternalIdentity externalUser, SignInMessage message) { return Task.FromResult<AuthenticateResult>(null); } public Task<AuthenticateResult> 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<AuthenticateResult>(null); } } catch { // Server error return Task.FromResult<AuthenticateResult>(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<IUserService, ActiveDirectoryUserService>(), // Don't need, but mandatory for idsvr3 ClientStore = new Registration<IClientStore, MyClientStore>(), ScopeStore = new Registration<IScopeStore, MyScopeStore>() }; return factory; }
即使我可以正常工作,是否也不需要与用户通过身份服务器提供的登录表单输入的凭据进行比较? (请参见下图):
我需要做什么才能从 IdentityServer3 登录页面提取用户凭据并针对 Active Directory 进行验证?
这是正确的方法吗?请提出建议。
感谢您的意见和建议。
提前谢谢您!
最佳答案
我会将 Active Directory 实现为 external identity provider .
这样,您就不必维护任何自定义代码,并且可以继续使用 AD 的 LDAP 功能(如果您被锁定)。您可以通过在 Identity Server 中禁用本地登录或使用 acr_values
中的 idp
值来使其成为您唯一的身份提供商。甚至在per client basis上.
关于c# - [C#、.NET] : Validating users via LDAP through IdentityServer3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38066039/