IdentityServer4 with asp.net core2.0 erron on AuthenticationOptions class

若如初见. 提交于 2019-12-07 03:09:26

That's correct - authentication middleware changed in asp.net core 2.0. I believe there is a release candidate of IndentityServer4.AccessTokenValidation for 2.0; however, at the moment, the Identity Server docs and samples have not been updated for 2.0.

One option is to use the Microsoft JwtBearer handler to secure your api. The IdentityServer4.AccessTokenValidation library uses this under the hood. It would look something like this (inside ConfigureServices()):

services.AddAuthentication(o =>
{
    o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(o =>
{
    o.Audience = "api1";
    o.Authority = "http://localhost:59391";
    o.RequireHttpsMetadata = false;
}); 

Another option is to update your code to use the IdentityServer4.AccessTokenValidation 2.0 rc. I haven't tried this yet but it would look something like this:

services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(o =>
{
    o.ApiName = "api1";
    o.Authority = "http://localhost:59391";
    o.RequireHttpsMetadata = false;
}); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!