Generated Client - Kiota preview
This KeycloakAdminApiClient
was generated using the Kiota library.
TIP
API Reference: Keycloak.AuthServices.Sdk.Kiota
NOTE
Kiota is a powerful command line tool developed by Microsoft that simplifies the process of generating API clients for calling any OpenAPI-described API. See OpenAPI Support for more details.
Getting Started
bash
dotnet add package Keycloak.AuthServices.Sdk.Kiota
csharp
/// <summary>
/// Adds <see cref="KeycloakAdminApiClient"/> for Keycloak Admin API.
/// </summary>
/// <returns>The IHttpClientBuilder for further configuration.</returns>
public static IHttpClientBuilder AddKeycloakAdminHttpClient(
this IServiceCollection services,
IConfiguration configuration,
Action<HttpClient>? configureClient = default,
string keycloakClientSectionName = KeycloakAdminClientOptions.Section
);
TIP
Kiota supports partial client generation, you can generate only the functionality you need. In this case, you can use source code of this library as an example.
Example
This is an example of how to use KeycloakAdminApiClient
together with Access Token Management.
cs
var options = configuration.GetKeycloakOptions<KeycloakAdminClientOptions>()!;
services.AddDistributedMemoryCache();
services
.AddClientCredentialsTokenManagement()
.AddClient(
tokenClientName,
client =>
{
client.ClientId = options.Resource;
client.ClientSecret = options.Credentials.Secret;
client.TokenEndpoint = options.KeycloakTokenEndpoint;
}
);
services
.AddKeycloakAdminHttpClient(configuration)
.AddClientCredentialsTokenHandler(tokenClientName);
var sp = services.BuildServiceProvider();
var client = sp.GetRequiredService<KeycloakAdminApiClient>();
var realmName = "Test";
var realm = await client.Admin.Realms[realmName].GetAsync();
realm.Should().NotBeNull();
realm!.Realm.Should().Be(realmName);