Samhammer.Authentication.Abstractions
6.0.0
See the version list below for details.
dotnet add package Samhammer.Authentication.Abstractions --version 6.0.0
NuGet\Install-Package Samhammer.Authentication.Abstractions -Version 6.0.0
<PackageReference Include="Samhammer.Authentication.Abstractions" Version="6.0.0" />
paket add Samhammer.Authentication.Abstractions --version 6.0.0
#r "nuget: Samhammer.Authentication.Abstractions, 6.0.0"
// Install Samhammer.Authentication.Abstractions as a Cake Addin
#addin nuget:?package=Samhammer.Authentication.Abstractions&version=6.0.0
// Install Samhammer.Authentication.Abstractions as a Cake Tool
#tool nuget:?package=Samhammer.Authentication.Abstractions&version=6.0.0
Samhammer.Authentication.Api
This provides a way to secure your api with keycloak jwt bearer authentication.
How to add this to your project:
- reference this nuget package: https://www.nuget.org/packages/Samhammer.Authentication.Api/
How to use:
Keycloak JWT Authentication
Add it to your api.
public void ConfigureServices(IServiceCollection services)
{
services.AddJwtAuthentication()
.AddKeycloak(Configuration);
}
public void Configure(IApplicationBuilder app)
{
app.UseAuthentication();
app.UseAuthorization();
}
Api calls requires auhorization header with an JWT token from keycloak.
POST https://myapi/action HTTP/1.1
Auhorization: Bearer JwtTokenContent
If you pass "IConfiguration" instead of "Action<ApiAuthOptions>" to "AddKeycloak" add the following to appsettings.json:
"ApiAuthOptions": {
"Issuer": "<<KeycloakTokenIssuerUrl>>",
"ClientId": "<<ClientIdRepresentingYourApp>>"
}
Guest Authentication
Add it to your api.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(GuestAuthenticationDefaults.AuthenticationScheme)
.AddGuest(Configuration);
}
Api calls requires header guestid with an "Version 4 UUID".
POST https://myapi/action HTTP/1.1
guestid: 1c11792b-538f-4908-992d-6570bb268e60
If you pass "IConfiguration" instead of "Action<GuestAuthOptions>" to "AddGuest" you can can override the default settings in appsettings.json:
"GuestAuthOptions": {
"Enabled": true,
"Name": "guest-[GuestID]",
"Role": "SomeGuestRole",
"Validator": "[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}"
}
Mixed Authentication
You can also setup both authentication types. In the example below jwt keycloak will be the default.
public void ConfigureServices(IServiceCollection services)
{
services.AddJwtAuthentication()
.AddKeycloak(Configuration)
.AddGuest(Configuration);
}
You can setup your supported authentication types on each controller action per attribute.
[HttpPost]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + ", " + GuestAuthenticationDefaults.AuthenticationScheme)]
public async Task<IActionResult> ActionForBoth()
{}
[HttpPost]
[Authorize(GuestAuthenticationDefaults.AuthenticationScheme)]
public async Task<IActionResult> ActionForGuests()
{}
Contribute
How to publish a nuget package
- Create a tag and let the github action do the publishing for you
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Samhammer.Authentication.Abstractions:
Package | Downloads |
---|---|
Samhammer.Authentication.Api
Keycloak authentication for .NET Core projects |
GitHub repositories
This package is not used by any popular GitHub repositories.