#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错误的更多相关文章

  1. 如何简单的在 ASP.NET Core 中集成 JWT 认证?

    前情提要:ASP.NET Core 使用 JWT 搭建分布式无状态身份验证系统 文章超长预警(1万字以上),不想看全部实现过程的同学可以直接跳转到末尾查看成果或者一键安装相关的 nuget 包 自上一 ...

  2. ASP.NET Core 简单集成签发 JWT (JSON Web Tokens)

    什么是 JWT ? 从 https://jwt.io/ 可以了解到对 JWT 的描述:JSON Web Tokens are an open, industry standard RFC 7519 m ...

  3. ASP.NET Core系列:JWT身份认证

    1. JWT概述 JSON Web Token(JWT)是目前流行的跨域身份验证解决方案. JWT的官网地址:https://jwt.io JWT的实现方式是将用户信息存储在客户端,服务端不进行保存. ...

  4. 10分钟简单学习net core集成jwt权限认证,快速接入项目落地使用

    什么是JWT JSON Web Token(JWT)是目前最流行的跨域身份验证.分布式登录.单点登录等解决方案. JWT的官网地址:https://jwt.io/ 通俗地来讲,JWT是能代表用户身份的 ...

  5. asp.net core 集成JWT(二)token的强制失效,基于策略模式细化api权限

    [前言] 上一篇我们介绍了什么是JWT,以及如何在asp.net core api项目中集成JWT权限认证.传送门:https://www.cnblogs.com/7tiny/p/11012035.h ...

  6. asp.net core 集成JWT(一)

    [什么是JWT] JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案. JWT的官网地址:https://jwt.io/ 通俗地来讲,JWT是能代表用户身份的令牌,可以使用JWT ...

  7. SpringBoot系列 - 集成JWT实现接口权限认证

    会飞的污熊 2018-01-22 16173 阅读 spring jwt springboot RESTful API认证方式 一般来讲,对于RESTful API都会有认证(Authenticati ...

  8. ASP.NET Core WebApi基于JWT实现接口授权验证

    一.ASP.Net Core WebApi JWT课程前言 我们知道,http协议本身是一种无状态的协议,而这就意味着如果用户向我们的应用提供了用户名和密码来进行用户认证,那么下一次请求时,用户还要再 ...

  9. ASP.NET Core 2.1 JWT Token 使用 (二) - 简书

    原文:ASP.NET Core 2.1 JWT Token 使用 (二) - 简书 接上文,https://www.jianshu.com/p/c5f9ea3b4b65 ASP.NET Core 2. ...

随机推荐

  1. html a标签链接点击闪动问题解决

    <a href="#">链接点击会闪动,解决: 这三种都可以用:<a href="javascript:;"></a>< ...

  2. [POJ3417]Network(LCA,树上差分)

    Network Description Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried ...

  3. POJ 3889 Fractal Streets(逼近模拟)

    $ POJ~3889~Fractal~Streets $(模拟) $ solution: $ 这是一道淳朴的模拟题,最近发现这种题目总是可以用逼近法,就再来练练手吧. 首先对于每个编号我们可以用逼近法 ...

  4. 01.helloworld--标签

    """参考网站:http://python.cocos2d.org/doc/programming_guide/index.html""" ...

  5. 【Java】SpringBoot的bean懒加载@Lazy注解

    注解说明 @Lazy:一般情况下,Spring容器在启动时会创建所有的Bean对象,使用@Lazy注解可以将Bean对象的创建延迟到第一次使用Bean的时候. 引用 在类上加入@Lazy或者@Lazy ...

  6. 【转】django 正则URL 匹配

    django 正则URL 匹配  转自:https://www.cnblogs.com/chenkeven/articles/9305260.html 一.引子 在day17 作业中,我们查看主机详细 ...

  7. xpath的几个常用规则

    我们在定位页面元素的时候呢,经常使用到xpath.xpah定位元素,我们可以使用开发者工具,然后右键选取元素的xpath ,但是这种方式得到的xpath是绝对路径,如果页面元素发生变动,经常会出现定位 ...

  8. xpath定位不到原因浅析

    在爬虫中,我们经常使用xpath来对元素进行定位,xpath定位分为两种,一种是绝对定位,/html/body/div[2]/div[1]/div/div[3]/a[7],另外一种是相对定位,比如r' ...

  9. content is not supported outside 'script" or asp content' region

    https://stackoverflow.com/questions/48915080/asp-net-content-is-not-supported-outside-the-script-or- ...

  10. nginx配置-Rewrite

    rewrite功能就是,使用nginx提供的全局变量或自己设置的变量,结合正则表达式和标志位实现url重写以及重定向.rewrite只能放在server{},location{},if{}中,并且只能 ...