TerevintoSoftware.AspNetCore.Authentication.ApiKeys 1.3.1

dotnet add package TerevintoSoftware.AspNetCore.Authentication.ApiKeys --version 1.3.1                
NuGet\Install-Package TerevintoSoftware.AspNetCore.Authentication.ApiKeys -Version 1.3.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TerevintoSoftware.AspNetCore.Authentication.ApiKeys" Version="1.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TerevintoSoftware.AspNetCore.Authentication.ApiKeys --version 1.3.1                
#r "nuget: TerevintoSoftware.AspNetCore.Authentication.ApiKeys, 1.3.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TerevintoSoftware.AspNetCore.Authentication.ApiKeys as a Cake Addin
#addin nuget:?package=TerevintoSoftware.AspNetCore.Authentication.ApiKeys&version=1.3.1

// Install TerevintoSoftware.AspNetCore.Authentication.ApiKeys as a Cake Tool
#tool nuget:?package=TerevintoSoftware.AspNetCore.Authentication.ApiKeys&version=1.3.1                

TerevintoSoftware.AspNetCore.Authentication.ApiKeys Coverage Status

This solution contains a set of classes and interfaces to add API Keys authentication to an ASP.NET Core application.
This solution is split into two packages:

Package Purpose
TerevintoSoftware.AspNetCore.Authentication.ApiKeys Contains main logic, depends on ASP.NET Core.
TerevintoSoftware.AspNetCore.Authentication.ApiKeys.Abstractions Contains interfaces used by the main package.

1. TerevintoSoftware.AspNetCore.Authentication.ApiKeys

This is the main package that contains the main classes and support for ASP.NET Core.
Since there are dependencies on classes from the Microsoft.AspNetCore.Authetication namespace, this contains only logic that should not change a lot under real usage.
Default implementations of some of the interfaces provided in the Abstractions package are in this package.

2. TerevintoSoftware.AspNetCore.Authentication.ApiKeys.Abstractions

This package contains interfaces that are needed by the main package:

  • IApiKeyFactory → used to generate new API Keys. Default implementation provided in main package.
  • IApiKeysCacheService → used to add and remove from cache the API Keys. This needs to be implemented by the consumer of the package.
  • IClaimsPrincipalFactory → used to create ClaimsPrincipals once a key is succesfully validated. Default implementation provided in main package.

Sample usage

A Web Application consuming this package is available in the Samples directory..

The default implementations can be injected as follows:

builder.Services
    .AddDefaultApiKeyGenerator(new ApiKeyGenerationOptions
    {
        KeyPrefix = "CT-",
        GenerateUrlSafeKeys = true,
        LengthOfKey = 36
    })
    .AddDefaultClaimsPrincipalFactory()
    .AddSingleton<IApiKeysCacheService, CacheService>() // CacheService is not provided
    .AddApiKeys();

An example key generated by that configuration is: CT-mTbC4r1Eh7wvXrXE1UDl18NGH1fRzcrRz.

How to build

  • Install Visual Studio 2022 (.NET 6 required), if needed.
  • Install git, if needed.
  • Clone this repository.
  • Build from Visual Studio or through dotnet build.

Bug reports and feature requests

Please use the issue tracker and ensure your question/feedback was not previously reported.

Product 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 1,855 7/30/2023
1.3.0 2,757 1/22/2023
1.2.1 1,551 7/3/2022
1.2.0 473 5/1/2022
1.1.0 468 3/20/2022
1.0.2 587 1/2/2022
1.0.1 303 1/2/2022
1.0.0 312 1/2/2022

[1.3.1]: Add package icon and license.
[1.3.0]: Add support to localize the error message on authentication failure.
[1.2.1]: Add missing license file.
[1.2.0]: Add support for Swagger UI.
[1.1.0]: Improve the API by removing unnecessary public surface and generating keys of the same length.
[1.0.0]: First release