Asp.net core 在ASP.NET 5 RC中完成OnAuthentication
我有一个ASP.NET 5 beta 8应用程序,它使用OpenIdConnect与Azure Active Directory集成。我尝试将应用程序更新为RC1,并将openid nuget包更改为Asp.net core 在ASP.NET 5 RC中完成OnAuthentication,asp.net-core,asp.net-core-mvc,azure-active-directory,openid-connect,Asp.net Core,Asp.net Core Mvc,Azure Active Directory,Openid Connect,我有一个ASP.NET 5 beta 8应用程序,它使用OpenIdConnect与Azure Active Directory集成。我尝试将应用程序更新为RC1,并将openid nuget包更改为“Microsoft.AspNet.Authentication.OpenIdConnect”:“1.0.0-RC1-final”。一切似乎都是正确的,但是我用来向我的ClaimsIdentity添加角色的OnAuthenticationComplete方法不再位于Events对象中,我找不到替代方
“Microsoft.AspNet.Authentication.OpenIdConnect”:“1.0.0-RC1-final”
。一切似乎都是正确的,但是我用来向我的ClaimsIdentity
添加角色的OnAuthenticationComplete
方法不再位于Events
对象中,我找不到替代方法。我如何使用新版本向我的身份添加声明
更新:更改为OnAuthenticationValidated
对我仍然不起作用。我的活动代码中一定有错误:
OnAuthenticationValidated = async notification =>
{
var claimsIdentity = notification.AuthenticationTicket.Principal.Identity as ClaimsIdentity;
var userRepository=new UserRepository(Configuration);
var userId = claimsIdentity?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var user = await userRepository.FindAsync(userId);
if (user == null)
{
await userRepository.AddAsync(new UserDto
{
UserId = userId,
Username = claimsIdentity?.FindFirst(ClaimTypes.Name)?.Value,
DisplayName = claimsIdentity?.FindFirst(ClaimTypes.Name)?.Value
});
}
claimsIdentity?.AddClaim(new Claim(ClaimTypes.Role, "super"));
}
另外,我用于登录的代码是:
[HttpGet]
public IActionResult Login()
{
if (HttpContext.User == null || !HttpContext.User.Identity.IsAuthenticated)
return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
return RedirectToAction("Index", "Home");
}
AuthenticationCompleted
事件已重命名为AuthenticationValidated
您可以在这张票上找到更多信息:。这是我的第一个想法,但它不起作用。我一定是做错了什么。我会用我的事件代码更新这个问题,“不工作”有点含糊不清。事件是否已触发?您是否尝试启用跟踪(在详细级别)以确定内部发生了什么?不会触发事件。我转到登录页面,但它没有调用事件就返回了。我试着回滚到beta 8版,结果成功了。在更新到RC1时,我只更改事件的名称并删除
options.DefaultToCurrentUriOnRedirect=true代码>因为属性不存在并且不再工作。有趣。如果使用TicketReceived
事件而不是AuthenticationValidated
,它是否有效?否,它不会被调用。我想我会从头开始这一部分(没有太多,所以可能比盲目改变要好…)。谢谢你的帮助。