我正在尝试使用OpenIddict核心DataProtection来设置ASP.NET,但是,在尝试启动应用程序时,我仍然会遇到异常:
InvalidOperationException: At least one encryption key must be registered in the OpenIddict server options. Consider registering a certificate using 'services.AddOpenIddict().AddServer().AddEncryptionCertificate()' or 'services.AddOpenIddict().AddServer().AddDevelopmentEncryptionCertificate()' or call 'services.AddOpenIddict().AddServer().AddEphemeralEncryptionKey()' to use an ephemeral key.
现在我明白了错误需要我做什么,我需要添加一个签名密钥/加密证书,但是为什么呢?
使用DataProtection的全部目的不是这个部分是自动化的,不需要您添加一个显式签名密钥/加密证书吗?根据文档,应该使用DataProtection加密除JWT令牌之外的所有密钥。
这是当前的代码:
if (authenticationOptions.DataProtection.TokenProtection.Enabled)
services
.AddDataProtection(options =>
{
options.ApplicationDiscriminator = applicationOptions.ShortName;
})
.SetApplicationName(applicationOptions.Name)
.SetDefaultKeyLifetime(TimeSpan.FromDays(authenticationOptions.DataProtection.TokenProtection.LifeTime))
.PersistKeysToAzureBlobStorage(CreateDataProtectionBlobClient(azureOptions.BlobStorageUrl, authenticationOptions.DataProtection, azureCredential))
.ProtectKeysWithAzureKeyVault(completeKeyVaultUri, azureCredential);
}
services.AddOpenIddict()
.AddCore(options =>
{
options.UseEntityFrameworkCore()
.UseDbContext<ApplicationDbContext>()
.ReplaceDefaultEntities<long>(); ;
})
.AddServer(options =>
{
options.SetAuthorizationEndpointUris("connect/auth");
options.SetTokenEndpointUris("/connect/token");
options.AllowAuthorizationCodeFlow();
options.AllowClientCredentialsFlow();
options.AllowRefreshTokenFlow();
options.UseAspNetCore()
.EnableAuthorizationEndpointPassthrough()
.EnableTokenEndpointPassthrough();
options.UseDataProtection();
//options.AddEphemeralSigningKey();
//options.AddEphemeralEncryptionKey();
})
.AddValidation(options =>
{
options.UseLocalServer();
options.UseAspNetCore();
options.UseDataProtection();
});
https://stackoverflow.com/questions/70318415
复制相似问题