public CurrentUser currentUser
{
get
{
CurrentUser result = new CurrentUser();
//jwt 解密token
IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);
string authHeader = this.Request.Headers["Authorization"];//Header中的token
// Add JWT Protection
if (authHeader != null && authHeader.StartsWith("Bearer"))
{
string token = authHeader.Substring("Bearer ".Length).Trim();
var requestService = HttpContext.RequestServices;
var conf = requestService.GetService(typeof(IConfiguration)) as IConfiguration;
var secretKey = conf["AAA:BBB"];//密钥信息
string resultstr = decoder.Decode(token, secretKey, verify: true);//token为之前生成的字符串 result = JsonConvert.DeserializeObject<CurrentUser>(resultstr);//反序列化 将jwt中的信息解压出来
}
else
{
//Handle what happens if that isn't the case
throw new Exception("The authorization header is either empty or isn't Basic.");
}
return result;
}
}

最新文章

  1. React-Native 组件开发方法
  2. 【转】logback 常用配置详解(序)logback 简介
  3. python随便笔记。。。
  4. 原生js arguments 用法
  5. Delphi是座宝山,有待挖掘
  6. Java知识点:琐碎知识点(2)
  7. VB程序逆向反汇编常见的函数
  8. flex toolTip样式设置
  9. Windows Live Writer 2014版绿色版制作及主题获取
  10. 第五章 服务容错保护:Spring Cloud Hystrix
  11. mybatis中两种取值方式?谈谈Spring框架理解?
  12. 第三十八篇-logcat的使用
  13. 01背包-dp
  14. 根据txt中的文件名将文件复制到目标文件夹中
  15. NOIP 2000 乘积最大
  16. 【java多线程】线程状态分析
  17. js中实现 复制到剪切板 功能
  18. 关于进行pdf的每页广告去除、转换word等方案。
  19. Snail—UI学习之得到某组件的方法
  20. PLT redirection through shared object injection into a running process

热门文章

  1. Ubuntu下解决MySQL自启动,chkconfig list 全部off 情况
  2. C++ 设置光标问题
  3. C#Winform的DEV下拉下拉控件介绍
  4. [leetcode]244. Shortest Word Distance II最短单词距离(允许连环call)
  5. APIView流程——请求方式分发
  6. php之$_SESSION的理解
  7. spring入门——applicationContext与BeanFactory的区别
  8. surf the internet scientifically
  9. Some Websites To Learning Laravel
  10. python 根据字符串内数字排序