Skip to content

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 Keycloak's REST API, including support for OpenID Connect, OAuth 2.0, and User-Managed Access (UMA 2.0).

License

Notifications You must be signed in to change notification settings

Black-Cockpit/NETCore.Keycloak

Repository files navigation

πŸ” Keycloak Client for .NET Core

Keycloak .NET Core Client Logo

πŸš€ 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.



GitHub Build Status NuGet version NuGet downloads GitHub Stars CodeFactor FOSSA Status Maintainability Rating Coverage Technical Debt Quality Gate Status Code Smells Reliability Rating Duplicated Lines (%) Vulnerabilities Bugs Security Rating Lines of Code License FOSSA Status


βš™οΈ 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

πŸ’» 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

  1. Add the Keycloak client to your services in Program.cs or Startup.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:

πŸ§ͺ 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

  1. Version Coverage:

    • Supports Keycloak 20.x through 26.x
    • Automated environment setup per version
    • Parallel version testing
  2. Test Categories:

    • Authentication flows
    • Authorization mechanisms
    • Client operations
    • Group management
    • User operations
  3. 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

About

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 Keycloak's REST API, including support for OpenID Connect, OAuth 2.0, and User-Managed Access (UMA 2.0).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages