- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用 Cookie 身份验证
的现有应用程序,我想添加使用 Active Directory
对用户进行身份验证的功能。当前应用程序使用基于 Cookie 的 authentication
和自定义 authorisation
- 数据库中的角色。
我正在从位于此处的示例中添加位:
Add sign-in with Microsoft to an ASP.NET Core web app
当我运行应用程序时出现错误:
System.InvalidOperationException: Scheme already exists: Cookies
配置 OpenIdConnect
和 Cookie 身份验证
的正确方法是什么。
//第 1 步基本 Cookie 验证
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Auth";
options.AccessDeniedPath = "/Home/AccessDenied";
options.Cookie.IsEssential = true;
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromSeconds(day/2.0);
options.Cookie.HttpOnly = true; // not accessible via JavaScript
options.Cookie.Name = "login_token";
options.TicketDataFormat = new CustomJwtDataFormat(
SecurityAlgorithms.HmacSha256,
tokenValidationParameters);
});
//第 2 步 OpenID Connect 身份验证
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"), "OpenIdConnect", "Cookies", true);
我找不到同时使用 Cookie 身份验证
和 OpenID Connect
的任何示例。这可能吗? 允许用户使用 Active Directory 身份验证或本地身份验证(详细信息存储在本地数据库中)有选择地登录。
更改“Cookie”名称后,去掉错误信息,但破坏了本地授权,例如
当给出有效的用户名和密码时,我通常授权登录。
HttpContext.Response.Cookies.Append("login_token", token, GetCookieOptions());
当前配置了 OpenIDConnect User.Identity.IsAuthenticated
仍然是错误的。
最佳答案
根据错误信息,它告诉你你有多个名为cookies的Scheme。
根据 AddMicrosoftIdentityWebApp 方法 document ,你会发现第三个参数名称是cookieScheme。
要使用的基于 cookie 的方案名称。默认情况下,它使用“Cookies”。
但是你已经在上面设置了这个名字,所以你应该使用其他的。例如:“ADCookies”。
如下所示:
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"), "OpenIdConnect", "ADCookies", true);
关于asp.net-core - ASP.NET Core 3.1 同时使用 OpenIDConnect 和自定义 Cookie 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65930262/
我正在 ASP.Net MVC C# 中开发一个依赖方,它应该在外部身份提供者中进行身份验证,我正在使用 Microsoft 的 owin 库。我遇到的问题是 Idp 没有公开元数据端点,即使我没有在
在过去的几天里,我一直在阅读有关 OAuth2 和 OpenIDConnect 的所有规范,并使用 Thinktecture Identity Server 实现了一个测试客户端。我还学习了几门复数类
在使用混合或授权代码流获取访问 token 以使其远离浏览器后,在(ASP.NET Core)OpenIdConnect 中间件中使用 SaveTokens = true 以便它们再次出现在浏览器中似
我已经使用 OpenIdConnect 通过 Azure AD 设置了一个 .NET Core 2.0 Web 应用(例如: https://github.com/Azure-Samples/acti
我已经使用 OpenIdConnect 通过 Azure AD 设置了一个 .NET Core 2.0 Web 应用(例如: https://github.com/Azure-Samples/acti
我在 ASP.NET Core 2.0 应用程序中使用 OpenIdConnectMiddleware,使用 Auth0 作为身份验证。 我关注了this guide通过Auth0实现认证,可以成功登
我有一个使用 Keycloak 注册的外部 openidconnect 身份提供商。当客户端应用程序尝试访问 protected 资源时,它会被重定向到 KeyCloak 登录页面。在登录页面上,我启
我正在尝试使用 couchbase DB 并使用授权代码流程为其设置身份验证。我按照此 link 中的步骤操作.我相应地准备了 ConfigJson。使用 Pods 我为 ios 安装了 Couchb
在 ASP.NET MVC 应用程序中,我正在尝试针对外部 OIDC 服务实现身份验证。对于我的测试,我使用 IdentityServer3 ( https://identityserver.gith
我在将 ASP.NET CORE 5.0 Web 应用程序与 OKTA 集成时遇到问题。我的公司需要将所有 Web 应用程序与 OKTA 集成。我写的这个应用程序作为 Linux 容器托管在 Farg
我试图实现 Multi-Tenancy 身份验证(我正在学习),到目前为止,我已经成功地在单租户中实现了我的应用程序的身份验证。 我用于单个租户的代码是 public void ConfigureA
我有一个 RP 没有明确要求您登录的情况。但是,我查看了 Open ID Connect 的 session 管理规范,更具体地说是 check_session_iframe端点规范草案here 我想
我想使用 对最终用户进行身份验证智威汤逊由 OpenId 提供连接提供程序,如 keycloak 或 auth0..etc 在 中istio 服务网格。但我可能无法成功集成它,因为我是 JWT aut
我们有多个租户,他们使用不同的权限(他们自己的,而不仅仅是标准提供商)。虽然我知道如何动态设置 clientId 和 secret,但我不知道如何设置权限。它在启动期间设置一次,之后无法更改(或者看起
目前,我在将 MVC 应用程序从 beta 3 迁移到 4 时遇到了多个问题 - 其中之一与 OpenIdConnect 到 Windows Azure 进行身份验证有关。当我转到具有授权属性的页面时
我有一个使用 ASP.NET Identity 运行的 IdentityServer4 应用程序。我想使用它,以便其他应用程序的用户可以通过我的远程身份服务器登录。 我已使用以下设置在身份服务器中配置
我正在尝试使用 OWIN Open ID Connect 中间件将我的 ASP.NET 应用程序的身份验证外包给 Azure Active Directory。应用程序在访问需要授权的页面时成功重定向
在 .Net 上,当我创建一个 Open ID 连接身份验证选项时,我有一个属性来设置 RedirectUri,这甚至按照文档中的建议定义,但 AspNetCore 上不存在这样的属性,它会自动设置为
普通 OpenIDConnect 服务器的工作方式如下: 你去 a.com/secure-resource 你从服务器得到一个302 您的浏览器处理它并将您发送到身份服务器 你在那里登录 它通过 PO
我不知道该使用哪个包: Microsoft.AspNet.Authentication.OpenIdConnect "1.0.0-beta4" Microsoft.AspNet.Security.Op
我是一名优秀的程序员,十分优秀!