Added the use of DEK's for encryption of secrets. Both the KEK's and DEK's are stored in a way that you can have multiple key of which one is active. But the others are still available for decrypting. This allows for implementing key rotation. Co-authored-by: eelke <eelke@eelkeklein.nl> Co-authored-by: Eelke76 <31384324+Eelke76@users.noreply.github.com> Reviewed-on: #6
49 lines
No EOL
1.5 KiB
C#
49 lines
No EOL
1.5 KiB
C#
using IdentityShroud.Core.Contracts;
|
|
using IdentityShroud.Core.Messages.Realm;
|
|
using IdentityShroud.Core.Model;
|
|
using IdentityShroud.Core.Services;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace IdentityShroud.Api;
|
|
|
|
public static class HttpContextExtensions
|
|
{
|
|
public static Realm GetValidatedRealm(this HttpContext context) => (Realm)context.Items["RealmEntity"]!;
|
|
}
|
|
|
|
// api: api/v1/realms/{realmId}/....
|
|
// api: api/v1/realms/{realmId}/clients/{clientId}
|
|
|
|
|
|
|
|
public static class RealmApi
|
|
{
|
|
public static void MapRealmEndpoints(IEndpointRouteBuilder erp)
|
|
{
|
|
var realmsGroup = erp.MapGroup("/api/v1/realms");
|
|
realmsGroup.MapPost("", RealmCreate)
|
|
.Validate<RealmCreateRequest>()
|
|
.WithName("Create Realm")
|
|
.Produces(StatusCodes.Status201Created);
|
|
|
|
var realmIdGroup = realmsGroup.MapGroup("{realmId}")
|
|
.AddEndpointFilter<RealmIdValidationFilter>();
|
|
|
|
ClientApi.MapEndpoints(realmIdGroup);
|
|
|
|
|
|
|
|
}
|
|
|
|
private static async Task<Results<Created<RealmCreateResponse>, InternalServerError>>
|
|
RealmCreate(RealmCreateRequest request, [FromServices] IRealmService service)
|
|
{
|
|
var response = await service.Create(request);
|
|
if (response.IsSuccess)
|
|
return TypedResults.Created($"/realms/{response.Value.Slug}", response.Value);
|
|
|
|
// TODO make helper to convert failure response to a proper HTTP result.
|
|
return TypedResults.InternalServerError();
|
|
}
|
|
} |