Implement jwks endpoint and add test for it.
This also let to some improvements/cleanups of the other tests and fixtures.
This commit is contained in:
parent
a80c133e2a
commit
ccb06b260c
24 changed files with 353 additions and 107 deletions
34
IdentityShroud.Api/Apis/Mappers/KeyMapper.cs
Normal file
34
IdentityShroud.Api/Apis/Mappers/KeyMapper.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System.Security.Cryptography;
|
||||
using IdentityShroud.Core.Contracts;
|
||||
using IdentityShroud.Core.Messages;
|
||||
using IdentityShroud.Core.Model;
|
||||
using IdentityShroud.Core.Security;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
namespace IdentityShroud.Api.Mappers;
|
||||
|
||||
public class KeyMapper(IEncryptionService encryptionService)
|
||||
{
|
||||
public JsonWebKey KeyToJsonWebKey(Key key)
|
||||
{
|
||||
using var rsa = RsaHelper.LoadFromPkcs8(key.GetPrivateKey(encryptionService));
|
||||
RSAParameters parameters = rsa.ExportParameters(includePrivateParameters: false);
|
||||
|
||||
return new JsonWebKey()
|
||||
{
|
||||
KeyType = rsa.SignatureAlgorithm,
|
||||
KeyId = key.Id.ToString(),
|
||||
Use = "sig",
|
||||
Exponent = WebEncoders.Base64UrlEncode(parameters.Exponent!),
|
||||
Modulus = WebEncoders.Base64UrlEncode(parameters.Modulus!),
|
||||
};
|
||||
}
|
||||
|
||||
public JsonWebKeySet KeyListToJsonWebKeySet(IEnumerable<Key> keys)
|
||||
{
|
||||
return new JsonWebKeySet()
|
||||
{
|
||||
Keys = keys.Select(e => KeyToJsonWebKey(e)).ToList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue