随着Core 1.1遵循@ blowdart的建议并实施了自定义中间件:
它的工作方式如下:
这有点适用于2.0,除了如果令牌无效(上面的步骤2)并且从未添加声明我得到"没有指定authenticationScheme,并且没有找到DefaultChallengeScheme."
所以现在我正在读取2.0中的auth更改:
https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x
在ASP.NET Core 2.0中我做同样的事情的正确途径是什么?我没有看到做真正的自定义身份验证的示例.
我正在使用DirectorySearcher在LDAP服务器中搜索用户条目.
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://myserver/OU=People,O=mycompany";
de.AuthenticationType = AuthenticationTypes.None;
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(uid=" + model.UserName + ")";
SearchResult result = deSearch.FindOne();
Run Code Online (Sandbox Code Playgroud)
我能够在结果变量中得到预期的输出.
但是,如果我尝试通过在目录条目中提供密码来验证同一用户,我总是会收到以下错误.
"用户名或密码不正确."
DirectoryEntry entry = new DirectoryEntry("LDAP://myserver/OU=People,O=mycompany", username, password);
DirectorySearcher search = new DirectorySearcher(
entry,
"(uid=" + username + ")",
new string[] { "uid" }
);
search.SearchScope = System.DirectoryServices.SearchScope.Subtree;
SearchResult found = search.FindOne(); ->>>>>this is where I get wrong credential error.
Run Code Online (Sandbox Code Playgroud)
用户名和密码适用于我要验证的用户.
任何人都可以告诉我这里我做错了什么或如何调试这个.
我正在使用 ASP.NET Core 2.1 React SPA Microsoft 模板。
我想使用 Active Directory 进行用户身份验证。我们的服务器使用 Active Directory 域标识在公司网络上运行。
我该怎么做?
我正在开发一个基于 .net core (2.2.103) 的应用程序,它必须连接到 LDAP 服务器。在运行 Windows 的开发机器上,我使用了System.DirectoryServices命名空间。但是,该应用程序必须在 Linux (Ubuntu) 上运行,并且我得到了一个PlatformNotSupportedException,所以我添加了一个引用
<PackageReference Include="Novell.Directory.Ldap" Version="2.2.1" />并使用了它。
不幸的是,PlatformNotSupportedException当连接被处理时,这会引发另一个(但由于线程中止):
Unhandled Exception: System.PlatformNotSupportedException: Thread abort is not supported on this platform.
at System.Threading.Thread.Abort()
at Novell.Directory.Ldap.Connection.Dispose(Boolean disposing, String reason, Int32 semaphoreId, InterThreadException notifyUser)
at Novell.Directory.Ldap.Connection.destroyClone(Boolean apiCall)
at Novell.Directory.Ldap.LdapConnection.Finalize()
Run Code Online (Sandbox Code Playgroud)
Linux 上的 dotnet core 是否有可靠的 LDAP 实现?
我的目标是检查用户是否是特定活动目录组的成员。
在.net mvc中,我在我的服务中使用了这段代码
HttpContext.Current.Request.LogonUserIdentity.Groups
.Any(x => x.Translate(typeof(NTAccount)).Value == "some role"
Run Code Online (Sandbox Code Playgroud)
效果很好。在.net core mvc 2.1.2中,我传递IHttpContextAccessor到服务构造函数并尝试使用以下内容
_httpAccessor.HttpContext.User.Identity.LogonUserIdentity.Groups
Run Code Online (Sandbox Code Playgroud)
但有一个问题,因为Identity不包含LogonUserIdentity. 我尝试找到任何解决方案,但没有成功,如何获取用户组列表或检查用户是否是特定组的成员?