예제 #1
0
        public static TokenModelJwt SerializeJwt(string jwtStr)
        {
            var jwtHandler            = new JwtSecurityTokenHandler();
            JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(jwtStr);
            object           role;

            try
            {
                jwtToken.Payload.TryGetValue(ClaimTypes.Role, out role);
            }
            catch (Exception e)
            {
                Console.WriteLine("jwthelper进入异常");
                Console.WriteLine(e);
                throw;
            }
            var tm = new TokenModelJwt
            {
                Uid  = Int64.Parse(jwtToken.Id),
                Role = role != null?role.ToString() : ""
            };

            return(tm);
        }
예제 #2
0
 public JwtHelper(IOptions <TokenModelJwt> tokenModel)
 {
     _tokenModel = tokenModel.Value;
 }