Example #1
0
        public static JwtEntity GetJwtEntity(string header)
        {
            JwtEntity jwtEntity = new JwtEntity();

            if (!string.IsNullOrEmpty(header))
            {
                var token = header.Split(' ');
                if (token.Length > 1)
                {
                    if (token[0].ToLower() == "bearer")
                    {
                        var jwtToken  = new JwtSecurityToken(token[1]);
                        var paloadStr = JSONHelper.Seriallize(jwtToken.Payload);
                        jwtEntity = JSONHelper.Dseriallize <JwtEntity>(paloadStr);
                        return(jwtEntity);
                    }
                    else
                    {
                        throw new Exception("无法识别的Authorization类型");
                    }
                }
                else
                {
                    throw new Exception("Authorization值不符合规范");
                }
            }
            return(null);
        }
Example #2
0
        public IActionResult UploadAvatar()
        {
            string code         = "000000";
            var    returnUpload = new ReturnUpload();

            try
            {
                IFormFileCollection Files = Request.Form.Files;
                if (Files == null || Files.Count == 0)
                {
                    code = "100051";
                }
                else
                {
                    string uploadStr = _uploadFileService.UploadImg(Files[0], _uploadSettings.path, _uploadSettings.avatar, HttpContext.GetIp(), GetJwtIEntity().UserId);
                    returnUpload = JSONHelper.Dseriallize <ReturnUpload>(uploadStr);
                }
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                code = "100050";
            }
            return(ReturnJson(code, returnUpload));
        }
Example #3
0
        public static JwtEntity GetJwtEntity(string header)
        {
            JwtEntity jwtEntity = new JwtEntity();

            if (!string.IsNullOrEmpty(header))
            {
                try
                {
                    var token = header.Split(' ');
                    if (token.Length > 1)
                    {
                        var jwtToken  = new JwtSecurityToken(token[1]);
                        var paloadStr = JSONHelper.Seriallize(jwtToken.Payload);
                        jwtEntity = JSONHelper.Dseriallize <JwtEntity>(paloadStr);
                        return(jwtEntity);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(null);
        }