An open API service indexing awesome lists of open source software.

https://github.com/ilyako/side-auth

.NET library that secures technical and DevOps endpoints without deploying heavy identity systems
https://github.com/ilyako/side-auth

api-key-authentication aspnet authentication authorization basic-auth minimal-api

Last synced: 11 days ago
JSON representation

.NET library that secures technical and DevOps endpoints without deploying heavy identity systems

Awesome Lists containing this project

README

          

# SideAuth

`SideAuth` is a library for ASP.NET Core designed to help developers protect specific Minimal API endpoints with HTTP Basic Authentication or API Keys using minimal configuration.

While operational endpoints—such as OpenAPI/Swagger/Scalar specifications, Prometheus metrics, or health checks—are typically restricted or excluded from production environments, certain deployment scenarios require them to remain accessible but protected. This library allows developers to secure these specific routes with a few lines of code directly during endpoint mapping.

## Usage

### 1. Install package

```bash
dotnet add package IlyaKo.AspNet.SideAuth
```

### 2. Register services
```csharp
services.AddBasicSideAuth("admin", "SecurePassword123");
services.AddApiKeySideAuth("prometheus-token");
```

### 3. Configure pipeline
```csharp
app.MapOpenApi().RequireBasicSideAuth();
app.MapScalarApiReference().RequireBasicSideAuth();
app.MapGet("/todos", async (ITodoService service) => await service.GetAll());
app.MapGet("/todos/{id:int}", async (int id, ITodoService service) => await service.GetByIdAsync(id));
app.MapGet("/metrics", () => "Metrics data").RequireApiKeySideAuth();
app.MapGet("/healthz", () => "Healthy").RequireAnySideAuth();
```

### Result

Based on the configuration above:
* **OpenAPI specifications** and **Scalar UI** require HTTP Basic Authentication (`admin` / `SecurePassword123`)
* **`/metrics`** requires `prometheus-token` passed in the default `X-API-Key` header
* **`/healthz`** accepts either HTTP Basic Authentication or the API Key
* **`/todo`** endpoints remain public