【发布时间】:2019-07-11 11:32:00
【问题描述】:
我已通过在我的Startup.cs 中调用services.AddMemoryCache() 注册IMemoryCache
我想做的是能够在我添加 JWT 身份验证的IServiceCollection 扩展方法中使用它。令牌的签名密钥存储在 Azure Keyvault 中,我想在检索密钥时缓存它
public static IServiceCollection AddJWTAuth(this IServiceCollection services)
{
services.AddAuthentication(options=>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwt =>
{
jwt .TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, tokenValidationParameters) =>
{
// Get signing from KV and add it to memory cache
// Use signing key from cache
}
};
});
return services;
}
有什么好的方法可以做到这一点?
【问题讨论】:
-
更明确地说明您要做什么。
-
@Nkosi 我已经添加了详细信息
标签: c# .net asp.net-core asp.net-web-api .net-core