码迷,mamicode.com
首页 > 其他好文 > 详细

jwt Token验证与解析

时间:2019-01-06 14:29:13      阅读:1808      评论:0      收藏:0      [点我收藏+]

标签:sig   ams   uil   aaaaaa   ret   div   .com   yii   die   

网上似乎没有相关代码

贴上一段Token的解析认证

[TestMethod]
        public void TestMethod1()
        {
            string Token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJMb2dpblR5cGUiOiLlvq7kv6HnmbvlvZUiLCJJc09uZSI6IkZhbHNlIiwiSUQiOiIxMDc2NDYyODY4OTQzMjEyNTQzIiwiUGhvbmUiOiIxMSIsIkVtYWlsIjoiMzMyMSIsIk9wZW5pZCI6IkJCIiwiTmFtZSI6IjEyMyIsIm5iZiI6MTU0Njc1MDQxOSwiZXhwIjoxNTQ2NzUyMjE5LCJpc3MiOiJUZXN0SXNzdWVyIiwiYXVkIjoiVGVzdEF1ZGllbmNlIn0._g3rfr2P3YEFRgKlxv_7DtnxkLq4CrfXBdEUHUDl9jc";
            /// 密匙
            string IssuerSigningKey = "AAAAAAAAAAAAAAAABBBBBBBBBVCCCCC==";

            /// 发行
            string ValidIssuer = "TestIssuer";

            /// 观众
            string ValidAudience = "TestAudience";

            var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(IssuerSigningKey));
            var tokenValidationParams = new TokenValidationParameters()
            {
                ValidateLifetime = true,
                ValidateAudience = true,
                ValidateIssuer = true,
                ValidateIssuerSigningKey = true,
                ValidIssuer = ValidIssuer,
                ValidAudience= ValidAudience,
                IssuerSigningKey = secretKey,
            };
            var jwtTokenHandler = new JwtSecurityTokenHandler();
            var a = jwtTokenHandler.ValidateToken(Token, tokenValidationParams, out SecurityToken validated);

        }

 

效果:

技术分享图片

 

jwt Token验证与解析

标签:sig   ams   uil   aaaaaa   ret   div   .com   yii   die   

原文地址:https://www.cnblogs.com/AnAng/p/10228394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!