Aes*_*eir 11 asp.net identityserver4
我正在学习IdentityServer4 https://identityserver4.readthedocs.io/en/release/quickstarts/0_overview.html,但似乎遇到了让它运行的问题.
在创建项目的API部分并进行相应配置之后:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ApiName = "api1"
});
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
'IApplicationBuilder' does not contain a definition for 'UseIdentityServerAuthentication' and no extension method 'UseIdentityServerAuthentication' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么建议?
编辑1:我注意到即使软件包已安装并存在,我也无法引用命名空间.
即
using IdentityServer4.AccessTokenValidation;
Run Code Online (Sandbox Code Playgroud)
要么
using IdentityServer4;
Run Code Online (Sandbox Code Playgroud)
Jer*_*ook 21
好吧,我刚关闭并重新打开Visual Studio 2017,问题就消失了.也许Visual Studio第一次在下拉IdentityServer4.AccessTokenValidation包时会窒息,重新打开项目会导致它再次尝试,这次它成功了.
小智 18
如果从net core 1.1迁移到2.0,则需要按照Identity Server:API迁移到ASP.NET Core 2中的描述迁移代码
在配置功能中
Before:
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ApiName = "apiApp"
});
After:
app.UseAuthentication();
Run Code Online (Sandbox Code Playgroud)
在ConfigureServices函数中
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme =
JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme =
JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(o =>
{
o.Authority = "http://localhost:5000";
o.Audience = "apiApp";
o.RequireHttpsMetadata = false;
});
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,我通过遵循IdentityServer 4 Quickstart Samples解决了这个问题,特别是Javascript Client示例。
所以,这就是它在这里的作用:
检查依赖版本。与.NET Core 2.0一起运行的 IdentityServer 报告了一些问题。在我的 API 项目中,我使用了Microsoft.Asp.NetCore.All 2.0.5 版和IdentityServer4.AccessTokenValidation 2.3.0 版。
在 Startup.cs 中,在 Configure 方法中添加: app.UseAuthentication(); 正如示例中所使用的那样。
最后一步是向 ConfigureServices 方法添加身份验证,如示例中所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
.AddJsonFormatters();
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.ApiName = "api1";
});
}
Run Code Online (Sandbox Code Playgroud)这在我的情况下解决了。希望它也适用于你,让我知道它是怎么回事。
快乐编码。
| 归档时间: |
|
| 查看次数: |
7547 次 |
| 最近记录: |