C# 如何在Startup.cs文件的ConfigureServices方法中的AddJwtBearer选项中设置动态IssuerSigningKey和TokenDecryptionKey
我用C# 如何在Startup.cs文件的ConfigureServices方法中的AddJwtBearer选项中设置动态IssuerSigningKey和TokenDecryptionKey,c#,jwt,asp.net-core-3.1,jwe,C#,Jwt,Asp.net Core 3.1,Jwe,我用dotnetcore3.1和Microsoft.IdentityModel.JsonWebTokens编写了一个身份验证webapi项目 我有3个客户端应用程序android,应用程序pwa和管理面板。每个客户端在数据库上都有特定的签名凭据和加密凭据密钥 当我想要生成访问令牌时,我使用其中一个客户端 var token = new SecurityTokenDescriptor() { Audience = client.Audience,
dotnetcore3.1
和Microsoft.IdentityModel.JsonWebTokens
编写了一个身份验证webapi
项目
我有3个客户端应用程序android
,应用程序pwa
和管理面板
。每个客户端在数据库上都有特定的签名凭据
和加密凭据
密钥
当我想要生成访问令牌时,我使用其中一个客户端
var token = new SecurityTokenDescriptor()
{
Audience = client.Audience,
Claims = claims,
Expires = DateTimeOffset.UtcNow.Add(client.AccessTokenLifeTime).DateTime,
Issuer = client.Issuer.GetDisplayName(),
CompressionAlgorithm = client.SupportCompression ? CompressionAlgorithms.Deflate : null,
IssuedAt = DateTime.UtcNow,
NotBefore = DateTime.UtcNow,
EncryptingCredentials =
new EncryptingCredentials(
new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(client.EncryptingKey)),
JwtConstants.DirectKeyUseAlg, SecurityAlgorithms.Aes256CbcHmacSha512),
SigningCredentials =
new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(client.SigningKey)),
SecurityAlgorithms.HmacSha256Signature),
};
在Startup.cs
文件中,我需要设置AddJwtBearer
选项
AddJwtBearer(x => x.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = false,
ValidateAudience = false,
TokenDecryptionKey =
new SymmetricSecurityKey(
Encoding.ASCII.GetBytes("encrypt_key")),
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("security_key"))
})
但我需要为每个客户端动态设置这些密钥
我该怎么做
谢谢