[英]Unable to verify Keycloak generated JWTs signed with es256
我正在嘗試將Keycloak用作OpenID提供程序。 由於合規性原因,我無法使用RSA,必須使用ECDSA密鑰對令牌進行簽名。 我正在使用ES256來簽署Keycloak生成的令牌。
我創建了一個簡單的asp.net核心服務器,需要對所有控制器進行身份驗證。 這是startup.cs
文件的一個示例:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
IdentityModelEventSource.ShowPII = true;
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options => {
options.RequireHttpsMetadata = false;
options.Authority = "[keycloak address]";
options.Audience = "hello";
});
services.AddSingleton<IAuthorizationHandler, DebugAuthorizationHandler>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.UseMvc();
}
}
我還有一個客戶端使用Keycloak執行身份驗證,接收訪問令牌,然后使用訪問令牌調用asp.net核心服務器。
服務器中的調用失敗,並顯示以下錯誤代碼:
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[1] Failed to validate the token.
Microsoft.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException: IDX10501: Signature validation failed.
使用RS256對令牌進行簽名時,相同的代碼成功。
有沒有人遇到過類似的問題?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.