SimpleAuthenticationTools.Abstractions
1.0.15
See the version list below for details.
dotnet add package SimpleAuthenticationTools.Abstractions --version 1.0.15
NuGet\Install-Package SimpleAuthenticationTools.Abstractions -Version 1.0.15
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="1.0.15" />
paket add SimpleAuthenticationTools.Abstractions --version 1.0.15
#r "nuget: SimpleAuthenticationTools.Abstractions, 1.0.15"
// Install SimpleAuthenticationTools.Abstractions as a Cake Addin #addin nuget:?package=SimpleAuthenticationTools.Abstractions&version=1.0.15 // Install SimpleAuthenticationTools.Abstractions as a Cake Tool #tool nuget:?package=SimpleAuthenticationTools.Abstractions&version=1.0.15
Simple Authentication for ASP.NET Core
A library to easily integrate Authentication in ASP.NET Core projects. Currently it supports JWT Bearer, API Key and Basic Authentication in both Controller-based and Minimal API projects.
Installation
The library is available on NuGet. Just search SimpleAuthenticationTools in the Package Manager GUI or run the following command in the Package Manager Console:
Install-Package SimpleAuthenticationTools
Usage Video
Take a look to a quick demo showing how to integrate the library:
Configuration
Authentication can be totally configured adding an Authentication section in the appsettings.json file:
"Authentication": {
"DefaultScheme": "Bearer", // Optional
"JwtBearer": {
"SchemeName": "Bearer" // Default: Bearer
"SecurityKey": "supersecretsecuritykey42!", // Required
"Algorithm": "HS256", // Default: HS256
"Issuers": [ "issuer" ], // Optional
"Audiences": [ "audience" ], // Optional
"ExpirationTime": "01:00:00", // Default: No expiration
"ClockSkew": "00:02:00", // Default: 5 minutes
"EnableJwtBearerService": true // Default: true
},
"ApiKey": {
"SchemeName": "MyApiKeyScheme", // Default: ApiKey
// You can specify either HeaderName, QueryStringKey or both
"HeaderName": "x-api-key",
"QueryStringKey": "code",
// Uncomment this line if you want to validate the API Key against a fixed value.
// Otherwise, you need to register an IApiKeyValidator implementation that will be used
// to validate the API Key.
//"ApiKeyValue": "f1I7S5GXa4wQDgLQWgz0",
"UserName": "ApiUser" // Required if ApiKeyValue is used
},
"Basic": {
"SchemeName": "Basic", // Default: Basic
// Uncomment the following lines if you want to validate user name and password
// against fixed values.
// Otherwise, you need to register an IBasicAuthenticationValidator implementation
// that will be used to validate the credentials.
//"UserName": "marco",
//"Password": "P@$$w0rd"
}
}
You can configure only the kind of authentication you want to use, or you can include all of them.
The DefaultScheme attribute is used to specify what kind of authentication must be configured as default. Allowed values are the values of the SchemeName attributes.
Registering authentication at Startup
using SimpleAuthentication;
var builder = WebApplication.CreateBuilder(args);
// ...
// Registers authentication schemes and services using IConfiguration information (see above).
builder.Services.AddSimpleAuthentication(builder.Configuration);
builder.Services.AddSwaggerGen(options =>
{
// ...
// Add this line to integrate authentication with Swagger.
options.AddSimpleAuthentication(builder.Configuration);
});
// ...
var app = builder.Build();
//...
// The following middlewares aren't strictly necessary in .NET 7.0, because they are automatically added
// when detecting that the corresponding services have been registered. However, you may need to call
// them explicitly if the default middlewares configuration is not correct for your app, for example
// when you need to use CORS.
// Check https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/middleware
// for more information.
//app.UseAuthentication();
//app.UseAuthorization();
//...
app.Run();
Samples
- JWT Bearer (Controller | Minimal API)
- API Key (Controller | Minimal API)
- Basic Authentication (Controller | Minimal API)
Contribute
The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo and we'll address them as we can.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 6.0.11 && < 7.0.0)
-
net7.0
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SimpleAuthenticationTools.Abstractions:
Package | Downloads |
---|---|
SimpleAuthenticationTools
A library to easily integrate Authentication in ASP.NET Core projects |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on SimpleAuthenticationTools.Abstractions:
Repository | Stars |
---|---|
marcominerva/SimpleAuthentication
A library to easily integrate Authentication in ASP.NET Core projects.
|
Version | Downloads | Last updated |
---|---|---|
2.1.5 | 476 | 10/9/2024 |
2.1.4 | 562 | 9/9/2024 |
2.0.15 | 191 | 9/2/2024 |
2.0.14 | 645 | 7/10/2024 |
2.0.13 | 4,460 | 5/15/2024 |
2.0.12 | 253 | 5/14/2024 |
2.0.11 | 2,032 | 1/10/2024 |
2.0.10 | 619 | 12/12/2023 |
2.0.9 | 3,425 | 7/10/2023 |
2.0.8 | 469 | 6/26/2023 |
2.0.7 | 437 | 6/14/2023 |
2.0.6 | 601 | 5/9/2023 |
2.0.3 | 1,608 | 4/4/2023 |
1.0.24 | 908 | 1/23/2023 |
1.0.23 | 656 | 1/11/2023 |
1.0.20 | 879 | 1/8/2023 |
1.0.15 | 1,180 | 12/1/2022 |
1.0.11 | 703 | 11/30/2022 |
1.0.5 | 1,678 | 11/9/2022 |
1.0.4 | 668 | 11/8/2022 |