【问题标题】:Is user has active session on IDMsrv?用户在 IDMsrv 上是否有活动会话?
【发布时间】:2018-02-05 05:52:01
【问题描述】:

如何验证 IDM 是否有用户登录的活动会话?

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

背景-

带有 aspnetIdentity 的 IDM 具有隐式授权的客户 (30 秒的身份令牌寿命,在不进入登录页面的情况下不断更新访问令牌,预计会在 IDM 上点击某些方法,然后我可以验证用户是否具有访问权限)!!

【问题讨论】:

    标签: identityserver4 asp.net-core-1.1


    【解决方案1】:

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

    有道理,为什么它不在 Idm 中。但至少在即将到来的版本中,它绝对有可能将此作为增强功能提供。

    Profile Service,IsActive 方法是被授权和命中的方法之一 令牌验证端点。

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

    只要会话处于活动状态(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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 2011-03-19
      相关资源
      最近更新 更多