NETCore.Keycloak
NETCore.Keycloak copied to clipboard
A comprehensive .NET Core client library for Keycloak that provides seamless integration with Keycloak's authentication and authorization services. This library offers a robust implementation of Keycl...
๐ Keycloak Client for .NET Core
๐ 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.
โ๏ธ Requirements
| Category | Supported Versions |
|---|---|
| .NET | 6.0, 7.0, 8.0 |
| Dependencies | ASP.NET Core, Microsoft.Extensions.DependencyInjection, Newtonsoft.Json |
โ Version Compatibility
| Keycloak Version | Support |
|---|---|
| 26.x | โ |
| 25.x | โ |
| 24.x | โ |
| 23.x | โ |
| 22.x | โ |
| 21.x | โ |
| 20.x | โ |
๐ Key Features
- ๐ 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
๐ Table of Contents
- ๐ Keycloak Client for .NET Core
- โ๏ธ Requirements
- โ Version Compatibility
- ๐ Key Features
- ๐ Table of Contents
- ๐ป Installation
- ๐ Getting Started
- ๐ Prerequisites
- ๐ง Basic Setup
- ๐ Basic Usage
- ๐ Documentation
- ๐งช Testing
- ๐ Test Documentation
- ๐ฌ Key Testing Features
- โก Running Tests
- ๐ค Contributing
- ๐ License
๐ป Installation
To integrate the Keycloak client library into your .NET Core application, simply add the NuGet package:
Install-Package Keycloak.NETCore.Client
๐ Getting Started
๐ Prerequisites
- โณ๏ธ .NET Core SDK (version 6.0 or later)
- ๐ฅ๏ธ A running Keycloak instance
- ๐ Client credentials and realm configuration
๐ง Basic Setup
- Add the Keycloak client to your services in
Program.csorStartup.cs:
services.AddKeycloakAuthentication(options =>
{
options.KeycloakBaseUrl = "http://localhost:8080";
options.RealmAdminCredentials = new KcClientCredentials
{
ClientId = "your-client-id",
ClientSecret = "your-client-secret"
};
});
๐ Basic Usage
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 });
๐ Documentation
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
-
๐ Monitoring and Metrics
- 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
๐งช Testing
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 Documentation
-
๐ Test Suite Guide
- Test patterns
- Setup instructions
- Mock data structure
-
๐ง Ansible Setup Guide
- Environment setup
- Configuration management
- Container orchestration
๐ฌ Key Testing Features
-
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
โก Running Tests
# Install test environment dependencies
cd NETCore.Keycloak.Client.Tests
make install_virtual_env
# Run tests for all supported versions
dotnet cake e2e_test.cake
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Contributing
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