Still working on getting client credential flow complete, most of the request works but still working on generating the JWT.
This commit is contained in:
parent
1a8c63808a
commit
8782ef39c6
80 changed files with 1331 additions and 414 deletions
|
|
@ -1,7 +1,7 @@
|
|||
using IdentityShroud.Api.Apis;
|
||||
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;
|
||||
|
||||
|
|
@ -19,31 +19,56 @@ public static class HttpContextExtensions
|
|||
|
||||
public static class RealmApi
|
||||
{
|
||||
public const string GetRealmRoute = "Get Realm";
|
||||
public const string CreateRealmRoute = "Create Realm";
|
||||
|
||||
public static void MapRealmEndpoints(IEndpointRouteBuilder erp)
|
||||
{
|
||||
var realmsGroup = erp.MapGroup("/api/v1/realms");
|
||||
|
||||
realmsGroup.MapPost("", RealmCreate)
|
||||
.Validate<RealmCreateRequest>()
|
||||
.WithName("Create Realm")
|
||||
.Produces(StatusCodes.Status201Created);
|
||||
.Produces(StatusCodes.Status201Created)
|
||||
.Validate<RealmCreateRequest>()
|
||||
.WithName(CreateRealmRoute);
|
||||
|
||||
|
||||
var realmIdGroup = realmsGroup.MapGroup("{realmId}")
|
||||
.AddEndpointFilter<RealmIdValidationFilter>();
|
||||
|
||||
ClientApi.MapEndpoints(realmIdGroup);
|
||||
|
||||
|
||||
realmIdGroup.MapGet("", RealmGet)
|
||||
.WithName(GetRealmRoute);
|
||||
|
||||
ClientApi.MapEndpoints(realmIdGroup);
|
||||
}
|
||||
|
||||
private static async Task<Results<Created<RealmCreateResponse>, InternalServerError>>
|
||||
|
||||
private static Ok<RealmRepresentation> RealmGet(
|
||||
Guid realmId,
|
||||
HttpContext context)
|
||||
{
|
||||
Realm realm = context.GetValidatedRealm();
|
||||
return TypedResults.Ok(MapToRepresentation(realm));
|
||||
}
|
||||
|
||||
private static async Task<Results<CreatedAtRoute<RealmRepresentation>, 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);
|
||||
|
||||
{
|
||||
var realm = response.Value;
|
||||
return TypedResults.CreatedAtRoute(
|
||||
MapToRepresentation(realm),
|
||||
GetRealmRoute,
|
||||
new { realmId = realm.Id });
|
||||
}
|
||||
|
||||
// TODO make helper to convert failure response to a proper HTTP result.
|
||||
return TypedResults.InternalServerError();
|
||||
}
|
||||
}
|
||||
|
||||
private static RealmRepresentation MapToRepresentation(Realm realm)
|
||||
=> new(realm.Id, realm.Slug, realm.Name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue