[英]Can't get JWT based security in .NET Core 3.0 working
根据MSDN ,我应该能够使用以下内容。
services.AddAuthentication()
.AddIdentityServerJwt();
这不起作用,因为AddIdentityServerJwt
似乎不存在。 另外,我不确定目前是否要与IdentityServer携手并进。
我还没有找到任何讨论.NET Core 3.0中基于后端的SPA的安全性的教程或博客,因此不会直接引用以上链接(因此依赖Identity Server)。 可能是因为目前它是一种最先进的技术。 从2.2到3.0的迁移手册并不详尽,我也怀疑它可能不准确 。
在以前的版本中,我将声明一个默认方案,并在Startup.cs文件中配置令牌验证。 但是,现在看来,所有奶酪都已经在Core 3中转移了。
我应该如何使用JWT配置(最简单的)安全性,并且(最好)避免使用Identity Server?
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAuthentication();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
//app.UseRouting();
app.UseAuthentication();
//app.UseAuthorization();
//app.UseEndpoints(e => e.MapControllers());
}
这会在Swagger中产生不同的跟随误差变化。
没有指定authenticationScheme,也没有找到DefaultChallengeScheme。
缺少的部分是,在调用AddAuthentication
,您还需要显式“选择加入” JWT承载:
public void ConfigureServices(IServiceCollection services)
{
...
services
.AddAuthentication()
.AddJwtBearer();
}
目前,该操作需要手动安装扩展方法,如[here]所示(Install-Package Microsoft.AspNetCore.Authentication.JwtBearer -Version 3.0.0-preview6.19307.2)。
安装软件包Microsoft.AspNetCore.Authentication.JwtBearer-版本3.0.0-preview6.19307.2
涵盖该方法的Core 3.0文档目前会重定向到Core 2.2的相应文档,并且由于预览状态可能随时更新或删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.