我正在使用asp.net核心2.0开发Identity Server 4。
在ConfigurationServices()方法中,我添加了:
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:59391",
RequireHttpsMetadata = false,
ApiName = "api1"
});
但是,它提供了编译错误:
引用类型'AuthenticationOptions‘声称它是在'Microsoft.AspNetCore.Authentication’中定义的,但是找不到。
当我查看程序集代码时:
namespace Microsoft.AspNetCore.Builder
{
public class IdentityServerAuthenticationOptions : Builder.AuthenticationOptions
{
// properties goes here
}
}
我是基于这个样本工程 (.net核心1.1)工作的,AuthenticationOptions
构建错误在这个Github链接中讨论了很多,但是看起来像Identity Server 4还没有完全支持asp .net核心2.0,这是真的吗?
请分享你的想法,如何解决这个错误或如何解决这个问题。
发布于 2017-09-22 12:03:29
这是正确的--在asp.net核心2.0中,身份验证中间件发生了变化。我相信有一个IndentityServer4.AccessTokenValidation 4.AccessTokenValationfor2.0的发布候选版本;但是,目前还没有更新身份服务器文档和示例。
一种选择是使用Microsoft处理程序来保护JwtBearer。IdentityServer4.AccessTokenValidation yServer4.AccessTokenVal环流库在掩码下面使用这一功能。它看起来像这样(在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;
});
另一种选择是更新代码以使用IdentityServer4.AccessTokenValidation 4.AccessTokenValentiing2.0RC。我还没试过这个,但看起来是这样的:
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(o =>
{
o.ApiName = "api1";
o.Authority = "http://localhost:59391";
o.RequireHttpsMetadata = false;
});
https://stackoverflow.com/questions/46368978
复制相似问题