我正在开发使用 Firebase 进行身份验证的移动应用程序,但我无法在 asp net core 2 应用程序上验证来自 Firebase 的 JWT,我遇到的问题是获取 IssuerSigningKey,这是我在 asp 网络核心启动类中的代码示例。从Firebase文档中,他们说我应该从 https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com 那里获得证书。我无法从那里继续
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:aud"],
IssuerSigningKey =
};
});
我终于从这个网站上找到了答案 https://blog.markvincze.com/secure-an-asp-net-core-api-with-firebase/我需要添加的只是选项。权限 = 配置["JWT:颁发者"];并删除颁发者签名密钥
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = Configuration["Jwt:Issuer"];
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:aud"],
};
});