更新时间:2023-02-17 10:08:58
更新: 在最近的测试版中,不再可能从 ConfigureServices
配置安全选项(除了 Identity).您现在需要在调用 app.UseJwtBearerAuthentication()
时直接配置 JWT 选项:
Update: in recent betas, configuring security options from ConfigureServices
is no longer possible (except for Identity). You now need to directly configure the JWT options when calling app.UseJwtBearerAuthentication()
:
public void Configure(IApplicationBuilder app) {
app.UseJwtBearerAuthentication(options => {
// Configure the JWT options here.
});
}
您忘记在管道中添加 OAuth2 不记名身份验证中间件:
You forgot to add the OAuth2 bearer authentication middleware in your pipeline:
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
app.UseStaticFiles();
app.UseOAuthBearerAuthentication();
app.UseIdentity();
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "api/{controller}/{action}/{id?}",
defaults: new {
controller = "Home",
action = "Index"
});
});
}
您也没有使用推荐的方法来注册 OAuth2 承载中间件使用的设置:
You're also not using the recommended approach to register the settings used by the OAuth2 bearer middleware:
public void ConfigureServices(IServiceCollection services) {
// Not recommended approach.
services.AddInstance(new OAuthBearerAuthenticationOptions { });
// Recommended approach.
services.ConfigureOAuthBearerAuthentication(options => {
// Configure the options used by the OAuth2 bearer middleware.
});
}