更新时间:2023-02-17 10:04:37
更新:在最近的测试版,从 ConfigureServices
配置安全选项是不不再可能(除了身份)。现在,您需要直接配置JWT选项时调用 app.UseJwtBearerAuthentication()
:
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.
});
}