Schick.Keycloak.RestApiClient
26.1.2
dotnet add package Schick.Keycloak.RestApiClient --version 26.1.2
NuGet\Install-Package Schick.Keycloak.RestApiClient -Version 26.1.2
<PackageReference Include="Schick.Keycloak.RestApiClient" Version="26.1.2" />
<PackageVersion Include="Schick.Keycloak.RestApiClient" Version="26.1.2" />
<PackageReference Include="Schick.Keycloak.RestApiClient" />
paket add Schick.Keycloak.RestApiClient --version 26.1.2
#r "nuget: Schick.Keycloak.RestApiClient, 26.1.2"
#addin nuget:?package=Schick.Keycloak.RestApiClient&version=26.1.2
#tool nuget:?package=Schick.Keycloak.RestApiClient&version=26.1.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 provided by Keycloak
Documentation for API Endpoints
- Official documentation: Keycloak Admin REST API
- Generated Swagger UI: Swagger Editor
Keycloak versions supported
Keycloak.RestApiClient | Keycloak |
---|---|
26.n.n | 26.x.x |
... | ... |
19.n.n | 19.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)
Authentication
You can select authentication flow either by the username and password or by providing client ID and client secret.
Sample code
With authentication by username/password
using FS.Keycloak.RestApiClient.Api;
using FS.Keycloak.RestApiClient.Authentication.ClientFactory;
using FS.Keycloak.RestApiClient.Authentication.Flow;
using FS.Keycloak.RestApiClient.ClientFactory;
var credentials = new PasswordGrantFlow
{
KeycloakUrl = "https://<keycloak-url>",
Realm = "<realm>",
UserName = "<username>",
Password = "<password>"
};
using var httpClient = AuthenticationHttpClientFactory.Create(credentials);
using var usersApi = ApiClientFactory.Create<UsersApi>(httpClient);
var users = await usersApi.GetUsersAsync("<realm>");
Console.WriteLine($"Users: {users.Count}");
With authentication by client-id/client-secret
using FS.Keycloak.RestApiClient.Api;
using FS.Keycloak.RestApiClient.Authentication.ClientFactory;
using FS.Keycloak.RestApiClient.Authentication.Flow;
using FS.Keycloak.RestApiClient.ClientFactory;
var credentials = new ClientCredentialsFlow
{
KeycloakUrl = "https://<keycloak-url>",
Realm = "<realm>",
ClientId = "<client-id>",
ClientSecret = "<client-secret>"
};
using var httpClient = AuthenticationHttpClientFactory.Create(credentials);
using var usersApi = ApiClientFactory.Create<UsersApi>(httpClient);
var users = await usersApi.GetUsersAsync("<realm>");
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));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- JsonSubTypes (>= 2.0.1)
- Newtonsoft.Json (>= 13.0.3)
- Polly (>= 8.1.0)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Schick.Keycloak.RestApiClient:
Package | Downloads |
---|---|
QuickJob.Users.Client
Package Description |
|
Be.Auto.Authentication.Keycloak.Role
ASP.NET Core Keycloak Integration |
|
Be.Auto.Servicestack.Authentication.Keycloak
Servicestack Keycloak Role Based Authentication |
|
Keycloak.Authz.Net.Resources
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
26.1.2 | 14,339 | 2 months ago |
26.0.7 | 9,041 | 3 months ago |
26.0.6 | 23,599 | 4 months ago |
26.0.2 | 25,436 | 6 months ago |
26.0.0 | 2,594 | 6 months ago |
25.0.0 | 116,873 | 10 months ago |
24.0.2 | 40,079 | 6/7/2024 |
24.0.2-beta1 | 112 | 6/6/2024 |
24.0.1 | 13,051 | 4/23/2024 |
24.0.0 | 321 | 4/20/2024 |
23.0.1 | 1,063 | 4/23/2024 |
23.0.0 | 250 | 4/20/2024 |
22.0.3 | 82,279 | 11/5/2023 |
22.0.2 | 275 | 11/4/2023 |
22.0.1 | 911 | 10/24/2023 |
22.0.0 | 2,246 | 10/3/2023 |
21.0.0 | 91,730 | 4/26/2023 |
20.0.3 | 8,251 | 2/22/2023 |
20.0.2 | 285 | 2/18/2023 |
20.0.1 | 356 | 12/30/2022 |
19.0.2 | 425 | 12/24/2022 |
19.0.1 | 365 | 11/7/2022 |
19.0.0 | 659 | 11/4/2022 |