Keycloak.NETCore.Clientv2 1.3.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Keycloak.NETCore.Clientv2 --version 1.3.2
                    
NuGet\Install-Package Keycloak.NETCore.Clientv2 -Version 1.3.2
                    
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="Keycloak.NETCore.Clientv2" Version="1.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Keycloak.NETCore.Clientv2" Version="1.3.2" />
                    
Directory.Packages.props
<PackageReference Include="Keycloak.NETCore.Clientv2" />
                    
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 Keycloak.NETCore.Clientv2 --version 1.3.2
                    
#r "nuget: Keycloak.NETCore.Clientv2, 1.3.2"
                    
#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 Keycloak.NETCore.Clientv2@1.3.2
                    
#: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=Keycloak.NETCore.Clientv2&version=1.3.2
                    
Install as a Cake Addin
#tool nuget:?package=Keycloak.NETCore.Clientv2&version=1.3.2
                    
Install as a Cake Tool

๐Ÿ” Keycloak Client for .NET Core

<div align="center"> <img src="assets/kc_logo.svg" alt="Keycloak .NET Core Client Logo" width="200"> </div>

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



<div align="center">

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


</div>

โš™๏ธ Requirements

Category Supported Versions
.NET 8.0, 9.0, 10.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
  • ๐Ÿ“Š Organizations support

๐Ÿ“š 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",
        Secret = "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",
        Secret = "your-client-secret"
    });

// Check for authentication errors
if (token.IsError)
{
    Console.WriteLine($"Authentication error: {token.ErrorMessage}");
    return;
}

// Get the actual token from the Response property
var accessToken = token.Response.AccessToken;
Console.WriteLine($"Successfully authenticated. Access token obtained.");

// Use the token for other operations
var users = await keycloakClient.Users.GetAsync(
    "your-realm",
    token.AccessToken,
    new KcUserFilter { Max = 10 });

๐Ÿ“Š Organizations

var client = new KeycloakClient("http://localhost:8080");
var token = await client.Auth.GetClientCredentialsTokenAsync(realm, credentials);

// Get count of all organizations
var count = await client.Organizations.CountAsync(realm, token.Response.AccessToken);

// List organizations with filter
var filter = new KcOrganizationFilter
{
    Search = "test",
    Exact = false,
    Max = 50
};
var orgs = await client.Organizations.ListAsync(realm, token.Response.AccessToken, filter);

// Get specific organization
var org = await client.Organizations.GetAsync(realm, token.Response.AccessToken, orgId);

๐Ÿ“Š Organization Members

var client = new KeycloakClient("http://localhost:8080");
var token = await client.Auth.GetClientCredentialsTokenAsync(realm, credentials);

// Get all members of an organization
var members = await client.Organizations.GetMembersAsync(
    realm,
    token.Response.AccessToken,
    organizationId);

// Get count of members
var count = await client.Organizations.GetMembersCountAsync(
    realm,
    token.Response.AccessToken,
    organizationId);

// Filter members by membership type
var filter = new KcOrganizationMemberFilter
{
    MembershipType = KcMembershipType.Managed,
    Search = "john",
    Exact = false,
    Max = 50
};
var managedMembers = await client.Organizations.GetMembersAsync(
    realm,
    token.Response.AccessToken,
    organizationId,
    filter);

// Add an existing user as a member of the organization
var addResult = await client.Organizations.AddMemberAsync(
    realm,
    token.Response.AccessToken,
    organizationId,
    userId);

// Invite a user by email (sends invitation or registration link)
var emailInvite = new KcInviteUserByEmailRequest
{
    Email = "user@example.com",
    FirstName = "John",
    LastName = "Doe"
};
var inviteByEmailResult = await client.Organizations.InviteUserByEmailAsync(
    realm,
    token.Response.AccessToken,
    organizationId,
    emailInvite);

// Invite an existing user to the organization (by user ID)
var inviteResult = await client.Organizations.InviteExistingUserAsync(
    realm,
    token.Response.AccessToken,
    organizationId,
    userId);

// Remove a member from the organization
var removeResult = await client.Organizations.RemoveMemberAsync(
    realm,
    token.Response.AccessToken,
    organizationId,
    memberId);

// Get all organizations associated with a member
var memberOrgs = await client.Organizations.GetMemberOrganizationsAsync(
    realm,
    token.Response.AccessToken,
    organizationId,
    memberId);

// Get full representation of member's organizations (not just brief)
var memberOrgsFilter = new KcOrganizationFilter
{
    BriefRepresentation = false
};
var memberOrgsFull = await client.Organizations.GetMemberOrganizationsAsync(
    realm,
    token.Response.AccessToken,
    organizationId,
    memberId,
    memberOrgsFilter);

๐Ÿ“š 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

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
1.4.0 136 2/20/2026
1.3.2 738 1/6/2026
1.3.1 99 1/6/2026
1.3.0 98 1/6/2026
1.2.0 104 1/6/2026
1.1.1 106 1/6/2026
1.1.0 130 12/30/2025