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

            try
            {
                jwtToken.Payload.TryGetValue(ClaimTypes.Role, out role);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
            var tm = new TokenModelJwt
            {
                Uid  = (jwtToken.Id).ObjToInt(),
                Role = role != null?role.ObjToString() : ""
            };

            return(tm);
        }