asp.net-core – 重新挑战ASP.NET Core中经过身份验证的用户
|
我在ASP.NET Core中遇到了一些身份验证管道问题.我的方案是我想向已经使用OpenID Connect和Azure AD进行身份验证的用户发出挑战.您可以在多种情况下执行此操作,例如在AAD v2端点方案中请求其他范围时. 这就像ASP.NET MVC中的魅力一样,但在ASP.NET Core MVC中,用户被重定向到cookie身份验证中间件中配置的Access Denied页面. (当用户未登录时,发出挑战按预期工作.) 在网上搜索并为我的中间件选项尝试不同的参数几个小时之后,我开始怀疑我要么缺少明显的东西,要么这种行为是设计的,我需要以其他方式解决我的要求.有人对此有任何想法吗? 编辑:我的Startup.cs的相关部分如下所示: public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(
SharedOptions => SharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
}
public void Configure(IApplicationBuilder app,IHostingEnvironment env,ILoggerFactory loggerFactory)
{
// <snip...>
app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme });
var options = new OpenIdConnectOptions
{
AuthenticationScheme = OpenIdConnectDefaults.AuthenticationScheme,ClientId = ClientId,Authority = Authority,CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"],ResponseType = OpenIdConnectResponseType.CodeIdToken,PostLogoutRedirectUri = "https://localhost:44374/",TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidateIssuer = false
}
};
options.Scope.Add("email");
options.Scope.Add("offline_access");
app.USEOpenIdConnectAuthentication(options);
}
Action看起来像这样: public void RefreshSession()
{
HttpContext.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme,new AuthenticationProperties { RedirectUri = "/" });
}
解决方法我在这里找到了一个提示和解决方案: https://github.com/aspnet/Security/issues/912.ChallengeBehavior.Unauthorized是“关键”. 这篇文章给出了当前(2016年11月 – ASPNet 1.0.1)的解决方法:https://joonasw.net/view/azure-ad-b2c-with-aspnet-core 您需要一个新的ActionResult才能使用ChallengeBehavior.Unauthorized行为调用AuthauticationManager.ChallengeAsync. 一旦问题https://github.com/aspnet/Mvc/issues/5187将成功关闭,这应该被整合. 我测试了它并且它运行得非常好(我的目标只是基于每个用户扩展Google范围). (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp-classic – 使用SMTP身份验证的经典ASP发送电子邮件
- asp.net-mvc – 在asp.net mvc中启动一组未选中的radiobutt
- 在Asp.net中运行外部可执行文件的内存限制
- ASP.NET Forms身份验证超时
- asp.net-mvc – Asp.net MVC:上传多个图像文件?
- asp.net – 发布网站时,我的默认文档名称不断从IIS中删除
- asp.net – DotLess的“web”属性究竟做了什么?
- asp.net – AJAX和FormsAuthentication,如何防止FormsAuthe
- asp.net – 我今天应该使用什么DOCTYPE?
- asp.net-mvc – MVC 4 HttpNotFound()和404错误
- asp.net-mvc – URL中的ASP.NET MVC冒号
- 如何在ASP.NET MVC中手动设置用户的角色?
- asp.net – 当内容页面位于子文件夹中时,jQuery无
- asp.net-mvc – 具有复杂路径的ASP.Net MVC – 如
- asp.net-mvc – 在asp.net mvc 3剃刀中识别html助
- ASP.NET MVC 4和ExtensionlessUrlHandler
- asp.net – 缓存解决方案
- asp.net-mvc – 是否可以使用实体框架代码首先设
- asp.net – VS插件:查看标记.存在这样的事情吗?
- asp.net – Internet Explorer 11在服务器端的检
