如何解决.NET core 3.1 api 允许 Cookie 和 JWT 身份验证 IdentityServer4
我们将 IdentityServer 4 与 JWT 身份验证用于 .NET Core 3.1 api。这一切正常。我正在尝试添加 NTLM 身份验证。
我安装了 IdentityServer 快速入门,并且能够获得“Windows”外部登录名以在域中对我进行身份验证。我看到正在设置 cookie,我看到我正在向 API 发送请求时发送 cookie,但我总是收到 401。我不确定如何设置 API 以接受 cookie。我正在使用 Angular 应用程序调用 API,但我不确定这在这里是否重要。感谢所有帮助。
客户端配置:
new Client {
RequireConsent = false,ClientId = "angular_spa",ClientName = "Angular SPA",AllowedGrantTypes = GrantTypes.Implicit,AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,IdentityServerConstants.StandardScopes.Profile,"externalapi"
},RedirectUris = {"http://localhost:42001/angular/logout"},PostlogoutRedirectUris = {"http://localhost:42001/"},AllowedCorsOrigins = {"http://localhost:42001"},AllowAccesstokensViabrowser = true,AccesstokenLifetime = 3600
},
身份服务器配置:
var builder = services.AddIdentityServer()
.AddInMemoryIdentityResources(keyConfig.Ids)
.AddInMemoryApiResources(keyConfig.Apis)
.AddInMemoryClients(keyConfig.Clients)
.AddCustomUserStore()
.AddInMemoryApiScopes(keyConfig.Scopes);
API 配置
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
options.Authority = Configuration.GetValue<string>("IdentityServerSettings:Authority");
options.ApiName = Configuration.GetValue<string>("IdentityServerSettings:ApiName");
options.ApiSecret = Configuration.GetValue<string>("IdentityServerSettings:ApiSecret");
});
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "Cookies";
})
.AddCookie("Cookies");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。