Schick.Keycloak.RestApiClient 20.0.2
.NET / C# Keycloak.RestApiClient
This is a .NET / C# REST API client
- for the Keycloak Admin REST API
- auto-generated by OpenAPI Generator
- using the OpenAPI definitions generated by Keycloak OpenApi Generator
Documentation for API Endpoints
- Official documentation: Keycloak Admin REST API
- Generated Swagger UI: Swagger Editor
Keycloak versions supported
Keycloak.RestApiClient | Keycloak |
---|---|
19.n.n | 19.x.x |
20.n.n | 20.x.x |
Frameworks supported
- .NET Core >=1.0
- .NET Framework >=4.6
- Mono/Xamarin >=vNext
Installation
Install from NuGet package
Install-Package Schick.Keycloak.RestApiClient
Getting Started
Method names
Method names are humanized:
GET
on path /{realm}/users
becomes GetUsers(Async)
GET
on path /{realm}/identity-provider/providers/{provider_id}
becomes GetIdentityProviderProvidersByProviderId(Async)
Sample code
using FS.Keycloak.RestApiClient.Api;
using FS.Keycloak.RestApiClient.Client;
using System;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class Program
{
private static async Task Main(string[] args)
{
using var httpClient = new KeycloakHttpClient("<authServerUrl>", "<admin_user>", "<password>");
using var usersApi = ApiClientFactory.Create<UsersApi>(httpClient);
var users = await usersApi.GetUsersAsync("MyRealm");
Console.WriteLine($"Users: {users.Count}");
}
}
}
Advanced Usage
To use the API client with a HTTP proxy, setup a System.Net.WebProxy
Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;
Connections
Each ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method.
To better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see here for details). To use your own HttpClient instance just pass it to the ApiClass constructor.
HttpClientHandler yourHandler = new HttpClientHandler();
HttpClient yourHttpClient = new HttpClient(yourHandler);
var api = new YourApiClass(yourHttpClient, yourHandler);
If you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory.
HttpClient yourHttpClient = new HttpClient();
var api = new YourApiClass(yourHttpClient);
You'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available.
Here an example of DI setup in a sample web project:
services.AddHttpClient<YourApiClass>(httpClient =>
new PetApi(httpClient));
Showing the top 20 packages that depend on Schick.Keycloak.RestApiClient.
Packages | Downloads |
---|---|
OElite.Core
Package Description
|
10 |
OElite.Core
Package Description
|
5 |
OElite.Core
Package Description
|
4 |
OElite.Core
Package Description
|
3 |
OElite.Core
Package Description
|
2 |
OElite.Core
Package Description
|
1 |
.NET Standard 2.0
- JsonSubTypes (>= 1.9.0)
- Newtonsoft.Json (>= 13.0.1)
- Polly (>= 7.2.3)
- System.ComponentModel.Annotations (>= 5.0.0)
Version | Downloads | Last updated |
---|---|---|
26.0.7 | 1 | 01/10/2025 |
26.0.6 | 0 | 12/02/2024 |
26.0.2 | 6 | 10/30/2024 |
26.0.0 | 0 | 10/18/2024 |
25.0.0 | 44 | 08/10/2024 |
24.0.2 | 2 | 09/08/2024 |
24.0.2-beta1 | 1 | 08/12/2024 |
24.0.1 | 7 | 08/26/2024 |
24.0.0 | 2 | 08/26/2024 |
23.0.1 | 2 | 09/08/2024 |
23.0.0 | 3 | 09/27/2024 |
22.0.3 | 2 | 08/12/2024 |
22.0.2 | 2 | 08/12/2024 |
22.0.1 | 0 | 10/24/2023 |
22.0.0 | 2 | 09/07/2024 |
21.0.0 | 2 | 08/26/2024 |
20.0.3 | 1 | 08/12/2024 |
20.0.2 | 2 | 09/08/2024 |
20.0.1 | 4 | 08/27/2024 |
19.0.2 | 3 | 10/31/2024 |
19.0.1 | 4 | 08/26/2024 |
19.0.0 | 3 | 09/07/2024 |