我需要一種方法通過IdentityServer3驗證組織內的用戶(使用LDAP和Active Directory),並授予他們對資源的訪問權限。[C#,.NET]:通過IdentityServer3通過LDAP驗證用戶
IdentityServer3似乎是OpenID Connect協議的實現框架,適用於身份驗證和授權。
到目前爲止,我已經能夠驗證硬編碼的用戶並使用InMemory實現獲取JWT(JSON Web令牌)訪問令牌。
請參考下面這個例子:
https://rajdeep.io/2015/05/07/creating-a-single-sign-on-using-thinktecture-identity-server-part-1/
但是,這不會是在我的情況非常有用,我就必須對用戶進行驗證(存儲在Active Directory)在大型組織中,併發給他們令牌訪問資源。
以下是我已經按照此鏈接
(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辦?
這是正確的做法嗎?請建議。
輸入和建議表示讚賞。
預先感謝您!
我正試圖用IdentityServer3來做同樣的事情。如果你有一段時間,你能幫我一把嗎? – blgrnboy