π A powerful and feature-rich .NET Core client library for Keycloak that simplifies integration with Keycloak's authentication and authorization services. This enterprise-ready library provides a comprehensive implementation of Keycloak's REST API, with full support for OpenID Connect, OAuth 2.0, and User-Managed Access (UMA 2.0) protocols.
Category | Supported Versions |
---|---|
.NET | 6.0, 7.0, 8.0 |
Dependencies | ASP.NET Core, Microsoft.Extensions.DependencyInjection, Newtonsoft.Json |
Keycloak Version | Support |
---|---|
26.x | β |
25.x | β |
24.x | β |
23.x | β |
22.x | β |
21.x | β |
20.x | β |
- π Complete Keycloak REST API integration
- π‘οΈ Robust security with OpenID Connect and OAuth 2.0
- π Built-in monitoring and performance metrics
- π Comprehensive error handling and debugging
- π¦ Automated token management and renewal
- π₯ Advanced user and group management
- π Multiple authentication flows support
- π Enterprise-grade scalability
- π Keycloak Client for .NET Core
To integrate the Keycloak client library into your .NET Core application, simply add the NuGet package:
Install-Package Keycloak.NETCore.Client
- β³οΈ .NET Core SDK (version 6.0 or later)
- π₯οΈ A running Keycloak instance
- π Client credentials and realm configuration
- Add the Keycloak client to your services in
Program.cs
orStartup.cs
:
services.AddKeycloakAuthentication(options =>
{
options.KeycloakBaseUrl = "http://localhost:8080";
options.RealmAdminCredentials = new KcClientCredentials
{
ClientId = "your-client-id",
ClientSecret = "your-client-secret"
};
});
Here's a quick example of how to use the library:
// Create Keycloak client
var keycloakClient = new KeycloakClient("http://localhost:8080");
// Authenticate
var token = await keycloakClient.Auth.GetClientCredentialsTokenAsync(
"your-realm",
new KcClientCredentials
{
ClientId = "your-client-id",
ClientSecret = "your-client-secret"
});
// Use the token for other operations
var users = await keycloakClient.Users.GetAsync(
"your-realm",
token.AccessToken,
new KcUserFilter { Max = 10 });
Explore our comprehensive documentation for each module:
-
π API Authentication
- JWT Bearer Authentication
- Role Claims Transformation
- Security Best Practices
-
π‘οΈ Authorization
- UMA 2.0 Authorization
- Policy Enforcement
- Protected Resources
-
π Response Types
- Type-safe responses
- Error handling
- Response Models
-
- Performance tracking
- Health checks
- System diagnostics
-
π Authentication Management
- Token lifecycle
- Multiple auth flows
- Security features
-
π₯ User Management
- User operations
- Role management
- Group handling
-
βοΈ Client Management
- Configuration
- Service accounts
- Client scopes
Our library includes an extensive test suite ensuring reliability across multiple Keycloak versions (20.x through 26.x). The testing infrastructure leverages Docker and Ansible for automated setup and execution.
-
π Test Suite Guide
- Test patterns
- Setup instructions
- Mock data structure
-
π§ Ansible Setup Guide
- Environment setup
- Configuration management
- Container orchestration
-
Version Coverage:
- Supports Keycloak 20.x through 26.x
- Automated environment setup per version
- Parallel version testing
-
Test Categories:
- Authentication flows
- Authorization mechanisms
- Client operations
- Group management
- User operations
-
Infrastructure:
- Docker-based environments
- Ansible automation
- Continuous Integration ready
- Comprehensive mock data
# Install test environment dependencies
cd NETCore.Keycloak.Client.Tests
make install_virtual_env
# Run tests for all supported versions
dotnet cake e2e_test.cake
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions from the community! Please check our Contributing Guidelines for details on:
- Branch naming conventions
- Code style and formatting rules
- Pull request process
- Security guidelines
β Star us on GitHub | π« Report Issues | π Read the Docs