Tingle.AspNetCore.Authentication 4.8.0

dotnet add package Tingle.AspNetCore.Authentication --version 4.8.0
NuGet\Install-Package Tingle.AspNetCore.Authentication -Version 4.8.0
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="Tingle.AspNetCore.Authentication" Version="4.8.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tingle.AspNetCore.Authentication --version 4.8.0
#r "nuget: Tingle.AspNetCore.Authentication, 4.8.0"
#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 Tingle.AspNetCore.Authentication as a Cake Addin
#addin nuget:?package=Tingle.AspNetCore.Authentication&version=4.8.0

// Install Tingle.AspNetCore.Authentication as a Cake Tool
#tool nuget:?package=Tingle.AspNetCore.Authentication&version=4.8.0

Tingle.AspNetCore.Authentication

Shared Key Authentication

This authentication logic mirrors the one for most Azure services such as Azure storage. Every request provides a different authentication value signed/encrypted with a key shared prior. This can often provide better security as compared to bearer tokens in OAuth/OpenId when introspection is not done on every request or when introspection can be very expensive.

Most common usage scenario is machine-to-machine authentication where the OAuth flow is expensive (introspection and renewing tokens).

A token is generated based on the HTTP method, path, time (if you want to enforce time constraints), content length and content type, then hashed using a pre-shared key (such as the primary or secondary key). The hashing algorithm used to generate the token is HMACSHA256.

A sample request to a resource that does shared key authentication: curl -H "Authorization: SharedKey 1/fFAGRNJru1FTz70BzhT3Zg" https://api.contoso.com/v1/cars?type=tesla

Add the following logic to Program.cs file

// Configure authentication
builder.Services.AddAuthentication()
                .AddSharedKey(options =>
                {
                   options.ValidationParameters.KeysResolver = (ctx) =>
                   {
                      var key1 = "my_primary_key_here";
                      var key2 = "my_secondary_key_here";
                      return Task.FromResult((IEnumerable<string>)new[] { key1, key2, /* add as many keys as you wish */ });
                   };
                })

builder.Service.AddAuthorization(options =>
{
   options.AddPolicy("MyTenantAuthorizationPolicy", policy =>
   {
      policy.AddAuthenticationSchemes(SharedKeyDefaults.AuthenticationScheme)
            .RequireAuthenticatedUser();
   });
});

var app = builder.Build();

// Add auth middleware
app.UseAuthentication();
app.UseAuthorization();

options are of type SharedKeyOptions. They contain authentication options used by SharedKeyTokenHandler. You can modify some of these configurations to suit your own application needs.

Now, we can use this functionality to authorize access to a controller as shown below:

[Authorize("MyTenantAuthorizationPolicy")]
public class DummyController : ControllerBase {}

Pass Through Authentication

This authentication scheme results in a successful authentication result by default. You can then use this authentication result to perform authorization to access various endpoints depending on their authorization requirements e.g by restricting the range of IP addresses.

Add the following logic in Program.cs file:

builder.Services.AddAuthentication()
                .AddPassThrough("my_scheme", null);

builder.Services.AddAuthorization(options =>
{
   options.AddPolicy("myProcessAuthPolicy", policy =>
   {
      policy.RequireAuthenticatedUser()
            .AddAuthenticationSchemes("my_scheme");
   });
});

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
   ...
   // Add auth middleware
   app.UseAuthentication();
   app.UseAuthorization();
   ....
}
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 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 is compatible.  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.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
4.8.0 0 5/5/2024
4.7.0 536 3/25/2024
4.6.0 368 3/8/2024
4.5.0 2,283 11/22/2023
4.4.1 250 11/20/2023
4.4.0 220 11/15/2023
4.3.0 672 10/18/2023
4.2.2 805 9/20/2023
4.2.1 1,186 8/4/2023
4.2.0 1,490 5/31/2023