A simple implementation of API Key authentication middleware in ASP.NET Core.
Useful for securing minimal APIs or internal endpoints with a shared key.
- Lightweight API key authentication middleware
- Easy to configure with minimal changes
- Suitable for internal tools, microservices, or prototyping
git clone https://github.com/ejimeoghenefejiro/WebAPIKeyAuth.git
cd WebAPIKeyAuth- Configure the API Key Set the expected API key in appsettings.json:
{
"ApiKey": "your-secure-api-key"
}- Use the Middleware Register the middleware in your Program.cs or Startup.cs:
app.UseMiddleware<ApiKeyMiddleware>();Example Request
GET /weatherforecast HTTP/1.1
Host: localhost:5000
X-API-KEY: your-secure-api-keyRunning the Project
dotnet runπ€ Contributing
Contributions and stars are welcome! β Feel free to fork the repo and submit a pull request.