-
Notifications
You must be signed in to change notification settings - Fork 4
/
ConfigureCertificatesOpenIddictServerOptions.cs
51 lines (44 loc) · 1.73 KB
/
ConfigureCertificatesOpenIddictServerOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Security.Cryptography.X509Certificates;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Server;
using TenantedOptions.Core;
namespace OAuthServer;
public class ConfigureCertificatesOpenIddictServerOptions : IConfigureTenantedOptions<OpenIddictServerOptions>
{
private readonly IConfiguration _configuration;
private readonly ILogger<ConfigureCertificatesOpenIddictServerOptions> _logger;
public ConfigureCertificatesOpenIddictServerOptions(
IConfiguration configuration,
ILogger<ConfigureCertificatesOpenIddictServerOptions> logger
)
{
_configuration = configuration;
_logger = logger;
}
public void Configure(string name, string tenant, OpenIddictServerOptions options)
{
_logger.LogInformation("Configuring OpenIddictServerOptions for tenant {tenant}", tenant);
string cerdata;
if (tenant.Equals("tenant1", StringComparison.OrdinalIgnoreCase))
{
cerdata = _configuration["OpenIddict:Certificate1"];
}
else
{
cerdata = _configuration["OpenIddict:Certificate2"];
}
var cer = new X509Certificate2(
Convert.FromBase64String(cerdata),
password: (string)null,
keyStorageFlags: X509KeyStorageFlags.EphemeralKeySet
);
var signingCertificate = cer;
options.SigningCredentials.Add(
new(new X509SecurityKey(signingCertificate), SecurityAlgorithms.RsaSha256)
);
var encryptionCertificate = cer;
options.EncryptionCredentials.Add(
new(new X509SecurityKey(encryptionCertificate), SecurityAlgorithms.RsaOAEP, SecurityAlgorithms.Aes256CbcHmacSha512)
);
}
}