예제 #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 ex)
            {
                Console.WriteLine(ex);
                throw;
            }
            var tm = new TokenModelJwt
            {
                Uid  = Convert.ToInt64(jwtToken.Id),
                Role = role != null?role.ToString() : ""
            };

            return(tm);
        }