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

Is user has active session on IDMsrv?

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

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

背景-

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

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

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

Profile Service, IsActive method is the one hit by authorize and tokenvalidation end point.

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

只要会话处于活动状态(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 重新启动并且用户未正确注销时,此方法有一些缺点。

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

更新:

idmsrv endpoints are missing security change check

Issue raised

Should be like this @tibold