KeycloakAuthZ.Caching 0.1.4

dotnet add package KeycloakAuthZ.Caching --version 0.1.4
                    
NuGet\Install-Package KeycloakAuthZ.Caching -Version 0.1.4
                    
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="KeycloakAuthZ.Caching" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KeycloakAuthZ.Caching" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="KeycloakAuthZ.Caching" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KeycloakAuthZ.Caching --version 0.1.4
                    
#r "nuget: KeycloakAuthZ.Caching, 0.1.4"
                    
#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.
#:package KeycloakAuthZ.Caching@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KeycloakAuthZ.Caching&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=KeycloakAuthZ.Caching&version=0.1.4
                    
Install as a Cake Tool

Keycloak Permission Cache

NuGet .NET License

Automatic caching for Keycloak permission checks in Blazor Server applications. Reduces Keycloak API calls by caching authorization results with two-level cache support (in-memory + distributed).

⚠️ Note: This library has not been tested in production environments.

Features

  • Automatic caching for [Authorize] policies using RequireProtectedResource
  • Two-level cache: Local (in-memory) + Distributed (Memory/Redis/SQL Server)
  • Zero code changes required for existing authorization logic
  • Optional IPermissionService for programmatic permission checks

Installation

dotnet add package KeycloakAuthZ.Caching

Quick Start

// Program.cs
builder.Services.AddKeycloakWebApiAuthentication(builder.Configuration);
builder.Services.AddKeycloakAuthorization(builder.Configuration);

// Add caching
builder.Services.AddPermissionService(options =>
{
    options.CacheDuration = TimeSpan.FromMinutes(10);
    options.LocalCacheDuration = TimeSpan.FromMinutes(1);
});
builder.Services.AddCachingDecorator();

Usage

// Define policies
builder.Services.AddAuthorizationBuilder()
    .AddPolicy("CanViewDocuments", policy =>
        policy.RequireProtectedResource("document", "view"));
@page "/documents"
@attribute [Authorize(Policy = "CanViewDocuments")]


Programmatic Checks (Optional)

@inject IPermissionService PermissionService

@code {
    private bool _canEdit;

    protected override async Task OnInitializedAsync()
    {
        _canEdit = await PermissionService.HasPermissionAsync("document", "edit");
    }
}

Configuration Options

Parameter Default Description
CacheDuration 10 min Distributed cache TTL
LocalCacheDuration 1 min Local cache TTL
UseSlidingExpiration true Extend TTL on access
UseLocalCache true Enable local cache

Redis Support

dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis
builder.Services.AddPermissionServiceWithRedis("localhost:6379");
builder.Services.AddCachingDecorator();

Documentation

See full documentation for detailed usage examples and API reference.

License

MIT

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
0.1.4 121 5/6/2026
0.1.3 108 5/4/2026
0.1.2 111 4/30/2026
0.1.1 106 4/30/2026
0.1.0 103 4/30/2026