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
- Host: GitHub
- URL: https://github.com/ilyako/side-auth
- Owner: IlyaKo
- License: mit
- Created: 2026-07-11T13:06:24.000Z (30 days ago)
- Default Branch: main
- Last Pushed: 2026-07-26T15:43:18.000Z (15 days ago)
- Last Synced: 2026-07-26T16:07:40.643Z (15 days ago)
- Topics: api-key-authentication, aspnet, authentication, authorization, basic-auth, minimal-api
- Language: C#
- Homepage: https://nuget.org/packages/IlyaKo.AspNet.SideAuth
- Size: 59.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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