码迷,mamicode.com
首页 > 移动开发 > 详细

JwtBearerAppBuilderExtensions.UseJwtBearerAuthentication(IApplicationBuilder

时间:2017-08-18 20:03:40      阅读:456      评论:0      收藏:0      [点我收藏+]

标签:npoi   参考   asp   server   issues   color   normal   use   nbu   

netcore从1.1升级到2.0时,出的错,因为使用的时Jwt token
参考https://github.com/aspnet/Security/issues/1310#issuecomment-314842779地址下的,

 

chris31389解答PinpointTownes 提问的问题,如下:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(options =>
        {
            options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
        })

        .AddJwtBearer(options =>
        {
            options.Authority = "http://localhost:30940/";
            options.Audience = "resource-server";
            options.RequireHttpsMetadata = false;
        });
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseAuthentication();

        // ...
    }
}

所以我的解决方案如下:将原本写在Configure中的函数拿到ConfigureServices下进行配置。
     services.AddAuthentication(options =>
            {
                options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
            })
       .AddJwtBearer(options =>
       {
           options.TokenValidationParameters = new TokenValidationParameters
           {
               IssuerSigningKey = TokenAuthOption.Key,
               ValidAudience = TokenAuthOption.Audience,
               ValidIssuer = TokenAuthOption.Issuer,
               ValidateIssuerSigningKey = true,
               ValidateLifetime = true,
               ClockSkew = TimeSpan.FromMinutes(0),
           };

       });
 

JwtBearerAppBuilderExtensions.UseJwtBearerAuthentication(IApplicationBuilder

标签:npoi   参考   asp   server   issues   color   normal   use   nbu   

原文地址:http://www.cnblogs.com/zinan/p/7391247.html

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