.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命令之 repeat 重复执行命令
$ vim ~/.bashrc function repeat() { number=$1 shift echo $@ for n in $(seq $number); do $@ done } $ ...
- keepalived的配置文件
! Configuration File for keepalived global_defs { notification_email { # acassen@firewall.loc # fail ...
- sigprocmask()函数学习笔记
sigprocmask()函数用于改变进程的当前阻塞信号集,也可以用来检测当前进程的信号掩码. 函数原型: int sigprocmask(int how, const sigset_t *restr ...
- css 表单头部固定
原创 https://blog.csdn.net/q3585914/article/details/69946478 table表头和首列的表格固定-CSS实现的Table表头固定 原创 2017年0 ...
- 机器学习:2.NPL自然语言处理
1. 词带的简单解释: 每一个词出现了多少次,缺点是不知道顺序 2.seq2seq自然语言处理的核心 RNN: 一对一:输入一个,输出一个 一对多:输入一个,输出多个 多对一:输入多个,输出一个 多对 ...
- -bash: findstr: command not found 问题解决
今天有个任务,需要获取apk的版本信息,百度之后说是之下下面的命令就行 adb shell dumpsys package com.baidu.searchbox | findstr versionC ...
- Atcoder2134 Zigzag MST
问题描述 We have a graph with N vertices, numbered 0 through N−1. Edges are yet to be added. We will pro ...
- unique && stl的全排列
stl的全排列: 看代码. #include<iostream> #include<cstdio> #include<algorithm> #include< ...
- CodeForces - 1183H Subsequences (hard version) (DP)
题目:https://vjudge.net/contest/325352#problem/C 题意:输入n,m,给你一个长度为n的串,然后你有一个集合,集合里面都是你的子序列,集合里面不能重复,集合中 ...
- Solr添加文档(XML)
在上一章中,我们学习解释了如何向Solr中添加JSON和.CSV文件格式的数据.在本章中,将演示如何使用XML文档格式在Apache Solr索引中添加数据. 示例数据 假设我们需要使用XML文件格式 ...