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" />
<PackageReference Include="KeycloakAuthZ.Caching" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=KeycloakAuthZ.Caching&version=0.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Keycloak Permission Cache
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 usingRequireProtectedResource - Two-level cache: Local (in-memory) + Distributed (Memory/Redis/SQL Server)
- Zero code changes required for existing authorization logic
- Optional
IPermissionServicefor 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
Automatic Caching (Recommended)
// 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 | Versions 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.
-
net10.0
- Keycloak.AuthServices.Authentication (>= 2.7.0)
- Keycloak.AuthServices.Authorization (>= 2.7.0)
- Microsoft.AspNetCore.Components.Web (>= 8.0.26)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.0)
-
net8.0
- Keycloak.AuthServices.Authentication (>= 2.7.0)
- Keycloak.AuthServices.Authorization (>= 2.7.0)
- Microsoft.AspNetCore.Components.Web (>= 8.0.26)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.0)
-
net9.0
- Keycloak.AuthServices.Authentication (>= 2.7.0)
- Keycloak.AuthServices.Authorization (>= 2.7.0)
- Microsoft.AspNetCore.Components.Web (>= 8.0.26)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.