SDKs
.NET SDK
Integrate Apikee API key authentication with ASP.NET Core middleware, authorization attributes, dependency injection, and Swashbuckle.
dotnet add package ApikeeConfigure
.NET binds Apikee__Secret to Apikee:Secret — a double underscore is a nested
key. The server-mode variables use the same names as the other SDKs and are read
automatically by AddApikee() when not set in code.
export Apikee__Secret=$(openssl rand -hex 32)
# Server mode (optional)
export APIKEE_BASE_URL=https://apikee.example.com/api/v1
export APIKEE_SERVER_KEY=sk_...
export APIKEE_PROJECT_ENV=payments-api-productionProgram.cs
builder.Services.AddApikee(o => {
o.Secrets = [builder.Configuration["Apikee:Secret"]!];
o.ServerKey = builder.Configuration["Apikee:ServerKey"]; // optional
o.ProjectEnv = builder.Configuration["Apikee:ProjectEnv"]; // optional
});
builder.Services.AddSwaggerGen(c => c.AddApikeeSecurityDefinition()); // 🔒 everywhere
var app = builder.Build();
app.UseApikee();Controllers
[ApiController, Apikee] // protects every action
public class UserController : ControllerBase
{
[HttpGet("/v1/users")]
public IActionResult List()
{
var claims = (ApikeeClaims) HttpContext.Items["apikee.claims"]!;
return Ok(new { claims.Tenant, claims.Scopes });
}
[HttpDelete("/v1/users/{id}"), Apikee(Scopes = "admin")]
public IActionResult Delete(string id) => Ok();
}Minimal APIs
app.MapGet("/v1/users", (HttpContext ctx) => {
var claims = (ApikeeClaims) ctx.Items["apikee.claims"]!;
return Results.Ok(new { claims.Tenant });
});Issuing keys
public class KeyController(ApikeeClient apikee) : ControllerBase
{
[HttpPost("/keys"), AllowAnonymous]
public async Task<IActionResult> Create([FromQuery] string tenant)
{
string key = await apikee.CreateAsync(tenant, keyOpts: new KeyOptions {
Tenant = tenant,
Scopes = ["read", "write"],
});
return StatusCode(201, new { key }); // returned once
}
}Describing endpoints
server.EnsureEndpointAsync("GET", "/v1/users", new EndpointMetadata
{
Description = "List users in the caller's tenant.",
Scopes = ["read:users"],
Tags = ["users"],
});Best-effort and asynchronous. See Endpoints.
Server client
var server = new ApikeeServerClient(new ApikeeServerOptions {
BaseUrl = "https://apikee.example.com/api/v1",
ServerKey = "sk_...",
ProjectEnv = "payments-api-production",
});
await server.CreateClientWithKeyAsync(new CreateClientOptions {
Name = "Acme mobile app",
ClientType = "company",
});
