Drop the X-Auth NuGet package in. Decorate your controller actions with [VerifyTransaction]. The bound transaction context is injected.
Pull XentraNet.XAuth.AspNetCore from nuget.org.
dotnet add package XentraNet.XAuth.AspNetCoreWire it up in Program.cs alongside the rest of your services.
using XentraNet.XAuth.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddXAuth(opts =>
{
opts.TenantId = builder.Configuration["XAuth:TenantId"];
});
var app = builder.Build();
app.MapControllers();
app.Run();[VerifyTransaction]Decorate any controller action that performs a sensitive operation. The filter validates the bearer, checks the action+amount, and rejects with 401 on mismatch.
using Microsoft.AspNetCore.Mvc;
using XentraNet.XAuth.AspNetCore;
[ApiController]
[Route("api/[controller]")]
public class TransferController : ControllerBase
{
[HttpPost]
[VerifyTransaction("transfer", Expect = new[] { "amount" })]
public IActionResult Transfer(
[FromBody] TransferRequest body,
[FromXAuth] TransactionContext ctx)
{
ledger.Transfer(body, ctx);
return Ok(new { ok = true });
}
}The bearer arriving at this endpoint comes from any X-Auth frontend SDK.
const { decision, access_token } = await advice({
action: 'transfer', amount: 2999, currency: 'USD',
});
await fetch('https://api.example.com/api/transfer', {
method: 'POST',
headers: { Authorization: `Bearer ${access_token}` },
body: JSON.stringify({ amount: 2999 }),
});Customize error handling, plug in CAEP signals, and tune your risk policy.