using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Svrnty.CQRS.Altcha.Abstractions; namespace Svrnty.CQRS.Altcha.MinimalApi; public static class EndpointRouteBuilderExtensions { /// /// Maps GET {routePrefix} (default /api/altcha/challenge) /// returning a fresh challenge in the JSON shape the /// altcha widget /// consumes via its challengeurl attribute. /// /// /// Requires an to be registered /// (typically by AddSvrntyAltchaGrpcVerifier(...)). The endpoint /// allows anonymous access — the whole point is gating mutations from /// unauthenticated callers, so the challenge endpoint must be reachable /// without credentials. /// public static IEndpointRouteBuilder MapSvrntyAltchaChallenge( this IEndpointRouteBuilder endpoints, string routePrefix = "/api/altcha/challenge") { endpoints.MapGet(routePrefix, async ( IAltchaChallengeProvider provider, CancellationToken cancellationToken) => { var challenge = await provider.CreateAsync(cancellationToken); return Results.Ok(new AltchaChallengeDto { Algorithm = challenge.Algorithm, Challenge = challenge.Challenge, Salt = challenge.Salt, Signature = challenge.Signature, MaxNumber = challenge.MaxNumber }); }) .AllowAnonymous() .WithName("Altcha_Challenge_Get") .WithTags("Altcha") .Produces(200) .Produces(503); return endpoints; } }