feat(api): add protected connect account endpoint
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
namespace FiscalOS.API.Accounts;
|
||||||
|
|
||||||
|
internal static class AccountsExtensions
|
||||||
|
{
|
||||||
|
private const string RouteGroupPrefix = "/accounts";
|
||||||
|
|
||||||
|
public static RouteGroupBuilder MapAccountsEndpoints(this WebApplication app)
|
||||||
|
{
|
||||||
|
var accountsGroup = app.MapGroup(RouteGroupPrefix).RequireAuthorization();
|
||||||
|
|
||||||
|
accountsGroup.MapConnectEndpoint();
|
||||||
|
|
||||||
|
return accountsGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace FiscalOS.API.Accounts.Connect;
|
||||||
|
|
||||||
|
internal static class Endpoint
|
||||||
|
{
|
||||||
|
private const string Route = "/connect";
|
||||||
|
|
||||||
|
public static RouteHandlerBuilder MapConnectEndpoint(this RouteGroupBuilder groupBuilder)
|
||||||
|
{
|
||||||
|
return groupBuilder.MapPost(Route, HandleAsync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<IResult> HandleAsync()
|
||||||
|
{
|
||||||
|
return Results.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,4 +37,6 @@ app.MapLoginEndpoint();
|
|||||||
app.MapRefreshEndpoint()
|
app.MapRefreshEndpoint()
|
||||||
.RequireAuthorization(Schemes.AllowExpiredTokens);
|
.RequireAuthorization(Schemes.AllowExpiredTokens);
|
||||||
|
|
||||||
|
app.MapAccountsEndpoints();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
@@ -2,6 +2,8 @@ global using System.ComponentModel.DataAnnotations;
|
|||||||
global using System.Security.Claims;
|
global using System.Security.Claims;
|
||||||
global using System.Text.Json.Serialization;
|
global using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
global using FiscalOS.API.Accounts;
|
||||||
|
global using FiscalOS.API.Accounts.Connect;
|
||||||
global using FiscalOS.API.Http;
|
global using FiscalOS.API.Http;
|
||||||
global using FiscalOS.API.Login;
|
global using FiscalOS.API.Login;
|
||||||
global using FiscalOS.API.Refresh;
|
global using FiscalOS.API.Refresh;
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace FiscalOS.API.Tests.Integration;
|
||||||
|
|
||||||
|
public class ConnectTests(TestApi testApi) : IntegrationTest(testApi)
|
||||||
|
{
|
||||||
|
private static readonly Uri ConnectUri = new("/accounts/connect", UriKind.Relative);
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Connect_WhenCalledWithoutValidToken_ItShouldReturn401WithProblemDetails()
|
||||||
|
{
|
||||||
|
var res = await Client.PostAsJsonAsync(ConnectUri, new { }, TestContext.Current.CancellationToken);
|
||||||
|
|
||||||
|
await res.Should().BeProblemDetails(HttpStatusCode.Unauthorized);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user