.net core 简单集成JWT报No authenticationScheme was specified, and there was no DefaultChallengeScheme found错误
#region JWT 认证
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
//.AddCustomAuth(o => { })
.AddJwtBearer(options => {
options.TokenValidationParameters = new TokenValidationParameters {
ValidIssuer = Configuration["JwtSetting:Issuer"],
ValidAudience = Configuration["JwtSetting:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtSetting:SecurityKey"])),
// 默认允许 300s 的时间偏移量,设置为0
ClockSkew = TimeSpan.Zero
};
});
#endregion
#region MVC修改控制器描述
services.AddHttpContextAccessor();
services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
services.AddMvc(config => {
config.RespectBrowserAcceptHeader = true;
//注入MVC拦截器
config.Filters.Add<ApiFilter>();
})
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new ContractResolver())
.AddJsonOptions(options => options.SerializerSettings.Converters.Add(new ChinaDateTimeConverter()))
.AddFormatterMappings(options => options.SetMediaTypeMappingForFormat("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.AddFormatterMappings(options => options.SetMediaTypeMappingForFormat("jpeg", "image/jpeg"))
.AddFormatterMappings(options => options.SetMediaTypeMappingForFormat("jpg", "image/jpeg"));
#endregion
在ConfigureServices中 注册JWT必须在注册MVC之前 否则就会报No authenticationScheme was specified, and there was no DefaultChallengeScheme found错误
app.UseAuthentication();
app.UseMvc();
在Configure中 添加JWT验证也必须在MVC之前,否则也会报错。
.net core 简单集成JWT报No authenticationScheme was specified, and there was no DefaultChallengeScheme found错误的更多相关文章
- 如何简单的在 ASP.NET Core 中集成 JWT 认证?
前情提要:ASP.NET Core 使用 JWT 搭建分布式无状态身份验证系统 文章超长预警(1万字以上),不想看全部实现过程的同学可以直接跳转到末尾查看成果或者一键安装相关的 nuget 包 自上一 ...
- ASP.NET Core 简单集成签发 JWT (JSON Web Tokens)
什么是 JWT ? 从 https://jwt.io/ 可以了解到对 JWT 的描述:JSON Web Tokens are an open, industry standard RFC 7519 m ...
- ASP.NET Core系列:JWT身份认证
1. JWT概述 JSON Web Token(JWT)是目前流行的跨域身份验证解决方案. JWT的官网地址:https://jwt.io JWT的实现方式是将用户信息存储在客户端,服务端不进行保存. ...
- 10分钟简单学习net core集成jwt权限认证,快速接入项目落地使用
什么是JWT JSON Web Token(JWT)是目前最流行的跨域身份验证.分布式登录.单点登录等解决方案. JWT的官网地址:https://jwt.io/ 通俗地来讲,JWT是能代表用户身份的 ...
- asp.net core 集成JWT(二)token的强制失效,基于策略模式细化api权限
[前言] 上一篇我们介绍了什么是JWT,以及如何在asp.net core api项目中集成JWT权限认证.传送门:https://www.cnblogs.com/7tiny/p/11012035.h ...
- asp.net core 集成JWT(一)
[什么是JWT] JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案. JWT的官网地址:https://jwt.io/ 通俗地来讲,JWT是能代表用户身份的令牌,可以使用JWT ...
- SpringBoot系列 - 集成JWT实现接口权限认证
会飞的污熊 2018-01-22 16173 阅读 spring jwt springboot RESTful API认证方式 一般来讲,对于RESTful API都会有认证(Authenticati ...
- ASP.NET Core WebApi基于JWT实现接口授权验证
一.ASP.Net Core WebApi JWT课程前言 我们知道,http协议本身是一种无状态的协议,而这就意味着如果用户向我们的应用提供了用户名和密码来进行用户认证,那么下一次请求时,用户还要再 ...
- ASP.NET Core 2.1 JWT Token 使用 (二) - 简书
原文:ASP.NET Core 2.1 JWT Token 使用 (二) - 简书 接上文,https://www.jianshu.com/p/c5f9ea3b4b65 ASP.NET Core 2. ...
随机推荐
- Linux-安装python3环境
Linux-安装python3环境 [root@node1 ~]# yum -y groupinstall "Development tools" [root@node1 ~]# ...
- amqp 抓包 不要在同一台机器
- Python语言为什么被称为高级程序设计语言?
Python是一种令人惊叹的编程语言,毫无疑问.从1991年的卑微开始,它现在几乎无处不在.无论您是在进行Web开发,系统管理,测试自动化,devop还是数据科学,Python在您的工作中发挥作用的可 ...
- VUE的双向绑定及局部组件的使用
vue的双向绑定,使用v-model,v-model只能使用在input textare select中 <!DOCTYPE html> <html lang="z ...
- 碎片记录——JMeter之 http post json对象与参数化调用,以及beanshell 引用Java源码
参考文档 http://jmeter.apache.org/usermanual/component_reference.html#samplers https://blog.csdn.net/qq_ ...
- hdu 4992 Primitive Roots 【求原根模板】
题目链接 大题流程: 判定是否有原根->求出最小原根->利用最小原根找出全部原根 #include<bits/stdc++.h> using namespace std; ty ...
- 【leetcode】301. Remove Invalid Parentheses
题目如下: 解题思路:还是这点经验,对于需要输出整个结果集的题目,对性能要求都不会太高.括号问题的解法也很简单,从头开始遍历输入字符串并对左右括号进行计数,其中出现右括号数量大于左括号数量的情况,表示 ...
- element中的表格处理:循环出表格数据
最近要做一个表格,但是为了方便维护,我们需要把表格数据循环出来,方便加减节点: <template> <el-table :data="tableData" st ...
- Vue项目【饿了么App】mock数据【data.json】
1.前后端分离式开发,约定好数据字段接口! 2.前端mock静态数据,开发完毕后,与后端进行数据联调! 3.vue.config.js 配置 devServer const appData = req ...
- AT3576 E Popping Balls——计数思路
题目:https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_e 题解:https://w ...