Be.Auto.Servicestack.Authentication.Keycloak 1.0.0

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

// Install Be.Auto.Servicestack.Authentication.Keycloak as a Cake Tool
#tool nuget:?package=Be.Auto.Servicestack.Authentication.Keycloak&version=1.0.0                

Be.Auto.Servicestack.Authentication.Keycloak

Servicestack Keycloak Role Based Authentication

This project demonstrates how to implement Keycloak role-based authentication in a ServiceStack application. The authentication is achieved using the KeycloakCredentialsAuthProvider and KeycloakOAuthProvider provided by the ServiceStack framework.

Usage

var authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[]
{
    new KeycloakCredentialsAuthProvider(AppSettings)
        .MapClaim(t => t.Roles, "role")
        .MapClaim(t => t.Permissions, "groups"),
    new KeycloakOAuthProvider(AppSettings)
        .MapClaim(t => t.Roles, "role")
        .MapClaim(t => t.Permissions, "groups")
});

Plugins.Add(authFeature);

if (HostingEnvironment.IsDevelopment())
{
    authFeature.MigrateKeycloakRoles(AppSettings);
}

KeycloakRequiredRole Attribute The KeycloakRequiredRole attribute is used to automatically validate the presence of a specific role in the request. Apply this attribute to the ServiceStack services or methods that require certain roles for access.

[KeycloakRequiredRole]
public class ProductService : Service
{
    public object Any(SaveProduct request)
    {
        return new ProductResponse
        {
            Result = request.Name
        };
    }

    public object Any(FindProduct request)
    {
        return new ProductResponse
        {
            Result = request.Name
        };
    }
}

Migration of Keycloak Roles During development, you can use the MigrateKeycloakRoles method to migrate Keycloak roles to your ServiceStack application. This ensures that your roles are synchronized with the Keycloak server.

if (HostingEnvironment.IsDevelopment())
{
    authFeature.MigrateKeycloakRoles(AppSettings);
}
Product Compatible and additional computed target framework versions.
.NET 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.

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.0.0 188 12/11/2023