Nous utilisons IdentityServer4 avec l’application Web .NET Core (" http://docs.identityserver.io/en/release/quickstarts/0_overview.html "). Nous avons remplacé AddDeveloperSigningCredential
par AddSigningCredential(CreateSigningCredential())
. Comme nous ne pouvons pas utiliser AddDeveloperSigningCredential
pour l’environnement de production, la production doit être remplacée par un matériel de clé persistant. Nous sommes nouveaux sur IdentityServer4 et notre question est la suivante: l’approche suivante permet-elle de créer des informations de signature sur l’environnement de production? Ou devons-nous y apporter des modifications?
Voici notre fichier startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
//connection string
string connectionString = Configuration.GetConnectionString("IdentityServer");
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer().AddDeveloperSigningCredential
.AddSigningCredential(CreateSigningCredential())
// this adds the config data from DB (clients, resources)
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
}) // this adds the operational data from DB (codes, tokens, consents)
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
// this enables automatic token cleanup. this is optional.
options.EnableTokenCleanup = true;
options.TokenCleanupInterval = 30;
});
}
private SigningCredentials CreateSigningCredential()
{
var credentials = new SigningCredentials(GetSecurityKey(), SecurityAlgorithms.RsaSha256Signature);
return credentials;
}
private RSACryptoServiceProvider GetRSACryptoServiceProvider()
{
return new RSACryptoServiceProvider(2048);
}
private SecurityKey GetSecurityKey()
{
return new RsaSecurityKey(GetRSACryptoServiceProvider());
}
Voici un moyen simple d’utiliser le certificat auto-signé X509.
Une façon d'utiliser un certificat auto-signé pour la signature de jeton avec IdentityServer4 consiste à stocker le certificat avec l'application dans le dossier 'wwwroot'.
public void ConfigureServices(IServiceCollection services)
{
.....other code .....
var fileName = Path.Combine(env.WebRootPath, "YOUR_FileName" );
if (!File.Exists(fileName))
{
throw new FileNotFoundException("Signing Certificate is missing!");
}
var cert = new X509Certificate2(fileName, "Your_PassPhrase" );
services.AddIdentityServer().AddSigningCredential(cert)
...other code.....
}