Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 在ASP.NET 5 RC中完成OnAuthentication_Asp.net Core_Asp.net Core Mvc_Azure Active Directory_Openid Connect - Fatal编程技术网

Asp.net core 在ASP.NET 5 RC中完成OnAuthentication

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对象中,我找不到替代方

我有一个ASP.NET 5 beta 8应用程序,它使用OpenIdConnect与Azure Active Directory集成。我尝试将应用程序更新为RC1,并将openid nuget包更改为
“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
,它是否有效?否,它不会被调用。我想我会从头开始这一部分(没有太多,所以可能比盲目改变要好…)。谢谢你的帮助。