ApiLocksmith is a collection of C# libraries that simplify API development with ASP.NET Core by providing easy integration of ApiKey-based authentication and Swagger documentation.
The ApiLocksmith.Core
library allows you to add ApiKey-based authentication to your minimal APIs built with ASP.NET Core. It provides a flexible and easy-to-use solution for securing your APIs.
To use ApiLocksmith.Core
, follow these steps:
-
Install the NuGet package:
dotnet add package ApiLocksmith.Core
-
Configure the ApiKeyOptions inside the
appsettings.json
:{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "ApiKeySettings": { "ApiKey": "MySecretApiKey", "ApiKeyHeaderName": "x-api-key", "ApiKeySchemeName": "ApiKey" } }
-
Add this to your
Program.cs
:builder.Services.AddApiKeyAuthenticationScheme(builder.Configuration, "ApiKeySettings");
Refer to the ApiLocksmith.Core documentation for detailed configuration options and usage examples.
The ApiLocksmith.Swagger.FastEndpoints
library extends ApiLocksmith.Core
by providing Swagger documentation integration with the FastEndpoints library for your APIs secured with ApiKey-based authentication.
To use ApiLocksmith.Swagger.FastEndpoints
, follow these steps:
-
Install the NuGet package:
dotnet add package ApiLocksmith.Swagger.FastEndpoints
-
Add this to your
Program.cs
:builder.Services.AddSwaggerDocumentWithApiKeyAuth(builder.Configuration, "ApiKeySettings"); // ... app.UseSwaggerGen();
Refer to the ApiLocksmith.Swagger.FastEndpoints documentation for detailed configuration options and usage examples.
Check out the examples folder for sample projects demonstrating the usage of ApiLocksmith libraries in different scenarios.
This project is licensed under the MIT License - see the LICENSE file for details.