【发布时间】:2025-12-13 11:15:01
【问题描述】:
【问题讨论】:
-
你的错误信息是什么?
-
请将您的代码粘贴为文本。图片更难搜索,因此更难回答
标签: c# asp.net api asp.net-core-2.0 bearer-token
【问题讨论】:
标签: c# asp.net api asp.net-core-2.0 bearer-token
ConfigureServices(IServiceCollection services)中的Startup.cs:
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = "Bearer";
})
.AddOAuthIntrospection("Bearer", o =>
{
o.Authority = new Uri(Configuration["URL"]);
o.Audiences.Add("Audiences");
o.ClientId = Configuration["OpenIdConnectOptions:ClientId"];
o.ClientSecret = Configuration["OpenIdConnectOptions:ClientSecret"];
}).AddOAuthIntrospection("Bearer2", o =>
{
o.Authority = new Uri(Configuration["URL"]);
o.Audiences.Add("Audiences");
o.ClientId = Configuration["OpenIdConnectOptions:ClientId2"];
o.ClientSecret = Configuration["OpenIdConnectOptions:ClientSecret2"];
});
全部在控制器上:
[Authorize(ActiveAuthenticationSchemes = "Bearer,Bearer2")]
[Route("[controller]")]
public class Controller : ControllerBase
{
【讨论】: