コード例 #1
0
            public async Task <CommonMessage> Logout(LogoutParam logoutParam, CancellationToken cancellation = default)
            {
                if (logoutParam.UserId == null)
                {
                    throw new Exception("请传入 options.userId,内容为要下线的用户 ID");
                }

                var res = await client.Host.AppendPathSegment("logout").SetQueryParams(new
                {
                    appId  = logoutParam.AppId,
                    userId = logoutParam.UserId
                }).WithHeaders(client.GetAuthHeaders()).WithOAuthBearerToken(client.Token).GetAsync(cancellation);

                return(new CommonMessage
                {
                    Code = 200,
                    Message = "强制登出成功"
                });
            }
コード例 #2
0
        public IActionResult Logout([FromBody] LogoutParam param)
        {
            var certification = HttpContext.Request.Headers["certification"];

            if (!UserRoleCache.TryGetUserRole(certification, out var userRole))
            {
                return(Ok());
            }
            var user = userRole.User;

            // 二次校验,防止利用奇怪的方法把别人踢下线
            if (user.UserName == param.UserName && user.UserPassword == param.Password)
            {
                UserRoleCache.RemoveUserRoleFromCache(certification);
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }