【发布时间】:2021-09-16 20:11:44
【问题描述】:
我有一个 asp.netcore .net 5 应用程序。
我已获得使用控制器端点上方的[Authorize] 属性的授权。
如何让它使用授权而不使用[Authorize] 属性?以下是我设置授权的方式:
我有这个在ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{...
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile("firebase_admin_sdk.json"),
});
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = "https://securetoken.google.com/vepo-xxx";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = "https://securetoken.google.com/vepo-xxx",
ValidateAudience = true,
ValidAudience = "vepo-xxx",
ValidateLifetime = true
};
});
...}
在我Configure 有:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, VepoContext context, ISearchIndexService searchIndexService)
{...
app.UseAuthentication();
app.UseAuthorization();
...}
【问题讨论】:
标签: asp.net asp.net-core .net-5 asp.net-authorization asp.net5