Tingle.AspNetCore.Authentication
4.11.1
See the version list below for details.
dotnet add package Tingle.AspNetCore.Authentication --version 4.11.1
NuGet\Install-Package Tingle.AspNetCore.Authentication -Version 4.11.1
<PackageReference Include="Tingle.AspNetCore.Authentication" Version="4.11.1" />
paket add Tingle.AspNetCore.Authentication --version 4.11.1
#r "nuget: Tingle.AspNetCore.Authentication, 4.11.1"
// Install Tingle.AspNetCore.Authentication as a Cake Addin #addin nuget:?package=Tingle.AspNetCore.Authentication&version=4.11.1 // Install Tingle.AspNetCore.Authentication as a Cake Tool #tool nuget:?package=Tingle.AspNetCore.Authentication&version=4.11.1
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 | 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 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. |
-
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.13.0 | 482 | 8/13/2024 |
4.12.0 | 158 | 8/7/2024 |
4.11.2 | 304 | 7/15/2024 |
4.11.1 | 359 | 6/26/2024 |
4.11.0 | 298 | 6/6/2024 |
4.10.1 | 80 | 6/5/2024 |
4.10.0 | 176 | 5/27/2024 |
4.9.0 | 301 | 5/16/2024 |
4.8.0 | 345 | 5/5/2024 |
4.7.0 | 572 | 3/25/2024 |
4.6.0 | 378 | 3/8/2024 |
4.5.0 | 2,291 | 11/22/2023 |
4.4.1 | 258 | 11/20/2023 |
4.4.0 | 226 | 11/15/2023 |
4.3.0 | 678 | 10/18/2023 |
4.2.2 | 816 | 9/20/2023 |
4.2.1 | 1,191 | 8/4/2023 |
4.2.0 | 1,498 | 5/31/2023 |