c# - Microsoft.Identity.Web AddMicrosoftIdentityWebApp - 无法设置 AccessDeniedPath
问题描述
我Microsoft.Identity.Web
在 .NET core 3.1 应用程序中使用该包(需要 LTS)。
我可以按照文档进行这项工作,但是我可以设置AccessDeniedPath
成功,但登录不会持续存在,或者路径没有设置。
我在这里尝试了这两种方法: https ://github.com/AzureAD/microsoft-identity-web/wiki/SameSite-Cookies
我还有通过外部方案登录的本地用户/角色。
我的启动目前看起来像:
添加标准身份
services.AddDefaultIdentity<ApplicationUser>()
.AddRoles<ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
添加 Azure ID
var azureAdConfig = Configuration.GetSection("AzureAD");
services.AddAuthentication()
.AddMicrosoftIdentityWebApp(options =>
{
options.ClientId = azureAdConfig["ClientId"];
options.TenantId = azureAdConfig["TenantId"];
options.Domain = azureAdConfig["Domain"];
options.Instance = azureAdConfig["Instance"];
options.CallbackPath = azureAdConfig["CallbackPath"];
options.SignedOutCallbackPath = azureAdConfig["SignedOutCallbackPath"];
//options.AccessDeniedPath = new PathString("/Account/AccessDenied");
}, options =>
{
options.AccessDeniedPath = new PathString("/Account/AccessDenied");
});
如果我更改services.AddAuthentication()
为,services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
则重定向有效,但是用户登录不会持续存在。
该代码将获取用户,从以下位置成功返回:
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: rememberMe);
但登录并没有继续让我认为这是一个 cookie 问题、命名错误等。
是我想要做的吗?或者我应该使用AddMicrosoft
身份验证并只检查域?由于此方法仅适用于公共端点(从我能找到的)。
解决方案
推荐阅读
- linux - 如何在 Assembly (x64/Linux) 中使用动态分配的内存?
- javascript - 使用javascript隐藏弹出窗口
- angular - 单个选择不适用于 p 表中的复选框
- postgresql - PostgreSQL 将自动增量添加到空 ID 列
- jupyter-lab - 如何在 Jupyterlab 中安装 sudo 命令以及用户 jovyan 的密码是什么?
- javascript - 如何获得离子内容的最大滚动高度?
- java - 如何创建构造函数以便我可以传递值
- html - 如何在 4 列网格中显示卡片?
- list - 如何在scala中将ListBuffer转换为List(不可变集合)
- php - 将参数传递给 crud 控制器 Backpack laravel