예제 #1
0
파일: JwtHelper.cs 프로젝트: liruisen/Blog
        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(e);
                throw;
            }
            var tm = new TokenModelJwt
            {
                Uid  = (jwtToken.Id).ObjToInt(),
                Role = role != null?role.ObjToString() : "",
            };

            return(tm);
        }