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
|
|
@ -1,13 +1,22 @@
|
|||
using FluentResults;
|
||||
using IdentityShroud.Api.Mappers;
|
||||
using IdentityShroud.Api.Validation;
|
||||
using IdentityShroud.Core.Messages;
|
||||
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"]!;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class RealmApi
|
||||
{
|
||||
public static void MapRealmEndpoints(this IEndpointRouteBuilder app)
|
||||
|
|
@ -18,7 +27,8 @@ public static class RealmApi
|
|||
.WithName("Create Realm")
|
||||
.Produces(StatusCodes.Status201Created);
|
||||
|
||||
var realmSlugGroup = realmsGroup.MapGroup("{slug}");
|
||||
var realmSlugGroup = realmsGroup.MapGroup("{slug}")
|
||||
.AddEndpointFilter<SlugValidationFilter>();
|
||||
realmSlugGroup.MapGet("", GetRealmInfo);
|
||||
realmSlugGroup.MapGet(".well-known/openid-configuration", GetOpenIdConfiguration);
|
||||
|
||||
|
|
@ -39,9 +49,15 @@ public static class RealmApi
|
|||
return TypedResults.InternalServerError();
|
||||
}
|
||||
|
||||
private static Task OpenIdConnectJwks(HttpContext context)
|
||||
private static async Task<Results<Ok<JsonWebKeySet>, BadRequest>> OpenIdConnectJwks(
|
||||
string slug,
|
||||
[FromServices]IRealmService realmService,
|
||||
[FromServices]KeyMapper keyMapper,
|
||||
HttpContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Realm realm = context.GetValidatedRealm();
|
||||
await realmService.LoadActiveKeys(realm);
|
||||
return TypedResults.Ok(keyMapper.KeyListToJsonWebKeySet(realm.Keys));
|
||||
}
|
||||
|
||||
private static Task OpenIdConnectToken(HttpContext context)
|
||||
|
|
@ -54,17 +70,12 @@ public static class RealmApi
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static async Task<Results<JsonHttpResult<OpenIdConfiguration>, BadRequest, NotFound>> GetOpenIdConfiguration(
|
||||
private static async Task<JsonHttpResult<OpenIdConfiguration>> GetOpenIdConfiguration(
|
||||
string slug,
|
||||
[FromServices]IRealmService realmService,
|
||||
HttpContext context,
|
||||
string slug)
|
||||
HttpContext context)
|
||||
{
|
||||
if (string.IsNullOrEmpty(slug))
|
||||
return TypedResults.BadRequest();
|
||||
|
||||
var realm = await realmService.FindBySlug(slug);
|
||||
if (realm is null)
|
||||
return TypedResults.NotFound();
|
||||
Realm realm = context.GetValidatedRealm();
|
||||
|
||||
var s = $"{context.Request.Scheme}://{context.Request.Host}{context.Request.Path}";
|
||||
var searchString = $"realms/{slug}";
|
||||
|
|
@ -94,30 +105,4 @@ public static class RealmApi
|
|||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// [HttpGet("")]
|
||||
// public ActionResult Index()
|
||||
// {
|
||||
// return new JsonResult("Hello world!");
|
||||
// }
|
||||
|
||||
// [HttpGet("{slug}/.well-known/openid-configuration")]
|
||||
// public ActionResult GetOpenIdConfiguration(
|
||||
// string slug,
|
||||
// [FromServices]LinkGenerator linkGenerator)
|
||||
// {
|
||||
// var s = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}";
|
||||
// var searchString = $"realms/{slug}";
|
||||
// int index = s.IndexOf(searchString, StringComparison.OrdinalIgnoreCase);
|
||||
// string baseUri = s.Substring(0, index + searchString.Length);
|
||||
//
|
||||
// return new JsonResult(baseUri);
|
||||
// }
|
||||
|
||||
// [HttpPost("{slug}/protocol/openid-connect/token")]
|
||||
// public ActionResult GetOpenIdConnectToken(string slug)
|
||||
//
|
||||
// {
|
||||
// return new JsonResult("Hello world!");
|
||||
// }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue