用户是否在IDMsrv上有活动会话?

时间:2017-08-28 01:52:34

标签: identityserver4 asp.net-core-1.1

如何验证IDM是否为用户登录设置了活动会话?

详细信息 - 如果用户'A'在浏览器'X'上有IDM上的活动会话,当同一用户'A'尝试使用浏览器'Y'登录时,预期行为会识别该用户具有活动会话并使浏览器无效'X'会话。

背景 -

带有aspnetIdentity的IDM  具有隐式授权的客户  (30秒身份识别生活,确实保持更新访问令牌而无需登录页面,预计会在IDM上点击某些方法然后我可以验证用户是否有权访问)!!

1 个答案:

答案 0 :(得分:0)

Brock has already mentioned about it, It should be at the time of login and logout

这有道理,为什么它不在Idm中。但它至少可以在未来的版本中将其作为增强功能提供。

  

Profile Service,IsActive方法是授权和命中的方法   tokenvalidation终点。

所以在登录持续会话时,然后当上面的代码点击时根据业务需求进行检查。

只要会话处于活动状态(cookie生存时间),静默身份验证将与应用程序逻辑一起传递。所以这也可以通过cookie生命周期来控制。

public override async Task IsActiveAsync(IsActiveContext context)
    {
        var sub = context.Subject.GetSubjectId();
        var user = await userManager.FindByIdAsync(sub);

        //Check existing sessions
        if (context.Caller.Equals("AccessTokenValidation", StringComparison.OrdinalIgnoreCase))
        {
            if (user != null)
                context.IsActive = !appuser.VerifyRenewToken(sub, context.Client.ClientId);
            else
                context.IsActive = false;
        }
        else
            context.IsActive = user != null;
    }

登录

 public async Task<IActionResult> Login(LoginInputModel model)
    {
        if (ModelState.IsValid)
        {

            // To enable password failures to trigger account lockout, set lockoutOnFailure: true
            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberLogin, false);
            if (result.Succeeded)
            {

                //Update security stamp to invalidate existing sessions 
                //TODO: This didn't invalidate the existing cookie from another client
                //var test= _userManager.UpdateSecurityStampAsync(_userManager.FindByEmailAsync(model.Email).Result).Result;


                appUser.PersistSession(new UserSession
                {
                    CreatedOn = DateTimeOffset.Now,
                    DeviceUniqueId = GetDeviceId(),
                    UserId = _userManager.FindByNameAsync(model.Email).Result.Id,
                    SId = httpContext.HttpContext.Session.Id, 
                    ClientId= httpContext.HttpContext.Request.QueryString.Value.GetClientIdFromQuery(),
                    ExpiresOn = DateTimeOffset.Now.AddMinutes(appSettings.SessionTimeOut)
                });                    
                _logger.LogInformation(1, "User logged in.");
                return RedirectToLocal(model.ReturnUrl);
            }

当IIS重新启动并且用户未正确注销时,此方法有一些缺点。

可能有更好的选择,这不是最合适的选择。

<强>更新 refer here duplicate/similar question

idmsrv endpoints are missing security change check

Issue raised

Should be like this @tibold

相关问题