如何让 OpenIdConnectAuthenticationMiddleware 验证签名证书的有效期?
How can I get OpenIdConnectAuthenticationMiddleware to validate the signing certificate validity dates?
我在混合流程中使用 Microsoft 的 OpenIdConnectAuthenticationMiddleware
针对 IdentityServer3。我将跳过 IdentityServer3 设置代码(因为我认为那里没有问题),但这里是依赖方启动代码:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
var options = new OpenIdConnectAuthenticationOptions
{
Authority = "https://localhost:44300/",
ClientId = "hybridclient",
ClientSecret = "secret",
RedirectUri = "https://localhost:44301/",
ResponseType = "code id_token",
SignInAsAuthenticationType = "Cookies",
Scope = "openid profile"
};
app.UseOpenIdConnectAuthentication(options);
我注意到当 IdentityServer3 使用过期的证书进行签名时——它允许,但尽职地记录为警告——证书的过期将被忽略并允许身份验证。这似乎是错误的。
我不知道这是谁的责任(OpenIdConnectAuthenticationMiddleware
?ADAL?)因为在我看来,签名证书过期时很容易出现身份验证失败。我一直查看代码,从 Katana 一直到 ADAL 中的 JwtSecurityTokenHandler
,但我看不到过期已检查。
我可以在 TokenValidationParameters.IssuerSigningKeyResolver
或 OpenIdConnectAuthenticationNotifications
上的 SecurityTokenValidated
通知中自己滚动一些东西,但看起来这应该是内置的东西。
有没有办法让 Microsoft OIDC 中间件验证签名证书到期?还是我遗漏了什么?
更新:根据 Brent 的回答,这显然是 gap in the functionality of JwtSecurityTokenHandler
that Microsoft would like to fill。我只能说我目前看到了这个,安装了 v4.0.0(因为它是 Microsoft.Owin.Security.OpenIdConnect
NuGet 包的依赖项)。
您需要从 JwtSecurityTokenHandler 派生,覆盖 ValidateIssuerSecurityKey 并检查签名。 OpenIdConnectOptions.SecurityTokenHandlers 可用于设置处理程序。
修复后,这会更容易。
https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/329
我在混合流程中使用 Microsoft 的 OpenIdConnectAuthenticationMiddleware
针对 IdentityServer3。我将跳过 IdentityServer3 设置代码(因为我认为那里没有问题),但这里是依赖方启动代码:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
var options = new OpenIdConnectAuthenticationOptions
{
Authority = "https://localhost:44300/",
ClientId = "hybridclient",
ClientSecret = "secret",
RedirectUri = "https://localhost:44301/",
ResponseType = "code id_token",
SignInAsAuthenticationType = "Cookies",
Scope = "openid profile"
};
app.UseOpenIdConnectAuthentication(options);
我注意到当 IdentityServer3 使用过期的证书进行签名时——它允许,但尽职地记录为警告——证书的过期将被忽略并允许身份验证。这似乎是错误的。
我不知道这是谁的责任(OpenIdConnectAuthenticationMiddleware
?ADAL?)因为在我看来,签名证书过期时很容易出现身份验证失败。我一直查看代码,从 Katana 一直到 ADAL 中的 JwtSecurityTokenHandler
,但我看不到过期已检查。
我可以在 TokenValidationParameters.IssuerSigningKeyResolver
或 OpenIdConnectAuthenticationNotifications
上的 SecurityTokenValidated
通知中自己滚动一些东西,但看起来这应该是内置的东西。
有没有办法让 Microsoft OIDC 中间件验证签名证书到期?还是我遗漏了什么?
更新:根据 Brent 的回答,这显然是 gap in the functionality of JwtSecurityTokenHandler
that Microsoft would like to fill。我只能说我目前看到了这个,安装了 v4.0.0(因为它是 Microsoft.Owin.Security.OpenIdConnect
NuGet 包的依赖项)。
您需要从 JwtSecurityTokenHandler 派生,覆盖 ValidateIssuerSecurityKey 并检查签名。 OpenIdConnectOptions.SecurityTokenHandlers 可用于设置处理程序。
修复后,这会更容易。 https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/329