Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
NikiforovAll committed May 5, 2024
1 parent 7a937f3 commit 2e6378a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default withMermaid({
]
},
{ text: 'OpenAPI Support', link: '/admin-rest-api/admin-api-openapi' },
{ text: 'Generated Client - Kiota', link: '/admin-rest-api/admin-api-kiota' },
]
},
{
Expand Down
28 changes: 28 additions & 0 deletions docs/admin-rest-api/admin-api-kiota.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated Client - Kiota <Badge type="warning" text="preview" />

This `KeycloakAdminApiClient` was generated using the *Kiota* library.

> [!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](/admin-rest-api/admin-api-openapi) for more details.
```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](/admin-rest-api/access-token).

<<< @/../tests/Keycloak.AuthServices.IntegrationTests/AdminKiota/KeycloakRealmKiotaClientTests.cs#GetRealmAsyncKiota_RealmExists_Success
2 changes: 2 additions & 0 deletions docs/admin-rest-api/admin-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ The full API documentation - <https://www.keycloak.org/docs-api/latest/rest-api/
💡**Alternatively**, you may want to use OpenAPI definition for Keycloak to generate a client based on your generator of choice - see [OpenAPI Support](/admin-rest-api/admin-api-openapi) for more details.

👍**Keycloak.AuthServices.Sdk.Kiota** provides out-of-the box client generated based on [Kiota](https://learn.microsoft.com/en-us/openapi/kiota/overview) - see [Generated Client - Kiota](/admin-rest-api/admin-api-kiota) for more details.

<<< @/../src/Keycloak.AuthServices.Sdk/Admin/IKeycloakClient.cs
15 changes: 12 additions & 3 deletions docs/admin-rest-api/admin-rest-api.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# HTTP Admin REST API

[Keycloak.AuthServices.Sdk](https://www.nuget.org/packages/Keycloak.AuthServices.Sdk) provides a typed HTTP Client to work with Keycloak Admin HTTP REST API.
[Keycloak.AuthServices](https://www.nuget.org/packages?q=Keycloak.AuthServices) has to options for integration with the Admin REST API.

| NuGet | Description |
|------|-------------|
| [Keycloak.AuthServices.Sdk](https://www.nuget.org/packages/Keycloak.AuthServices.Sdk) | Provides a typed HTTP Client to work with Keycloak Admin HTTP REST API. A high quality SDK client written manually, but not all functionality is implemented. |
| [Keycloak.AuthServices.Sdk.Kiota](https://www.nuget.org/packages/Keycloak.AuthServices.Sdk.Kiota) | A client generated based on OpenAPI Spec, **full functionality** covered|

The Admin REST API in Keycloak provides a programmatic way to manage and administer Keycloak instances. It allows you to perform various administrative tasks such as creating and managing realms, users, roles, clients, and more. To interact with the Admin REST API, you can use HTTP requests to send commands and retrieve data. The API follows the REST architectural style and is designed to be simple and intuitive to use.

Expand Down Expand Up @@ -31,10 +35,15 @@ You can use `IKeycloakClient` from Web APIs, Worker, Console apps, etc. It is fu
To add it to DI, you can use convenience extensions method `AddKeycloakAdminHttpClient`:

```csharp
/// <summary>
/// Adds <see cref="IKeycloakClient"/>, <see cref="IKeycloakRealmClient"/>, <see cref="IKeycloakUserClient"/>, <see cref="IKeycloakGroupClient"/> HTTP clients for Keycloak Admin API.
/// </summary>
/// <returns>The IHttpClientBuilder for further configuration.</returns>
public static IHttpClientBuilder AddKeycloakAdminHttpClient(
this IServiceCollection services,
KeycloakAdminClientOptions keycloakAdminClientOptions,
Action<HttpClient>? configureClient = default
IConfiguration configuration,
Action<HttpClient>? configureClient = default,
string keycloakClientSectionName = KeycloakAdminClientOptions.Section
)
```

Expand Down
11 changes: 6 additions & 5 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Keycloak.AuthServices is a [family of packages](https://www.nuget.org/packages?q

## Packages

| Package | Description |
| ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Keycloak.AuthServices.Authentication](https://www.nuget.org/packages/Keycloak.AuthServices.Authentication/2.0.0-pre-1) | As an OAuth2, OpenID Connect, and SAML compliant server, Keycloak can secure any application and service as long as the technology stack they are using supports any of these protocols. This library provides AspNetCore integration for JwtBearer and OpenIdConnect. |
| [Keycloak.AuthServices.Authorization](https://www.nuget.org/packages/Keycloak.AuthServices.Authorization/2.0.0-pre-1) | Provides Role-Based Access Control (RBAC) and integration with the Keycloak Authorization Server. |
| [Keycloak.AuthServices.Sdk](https://www.nuget.org/packages/Keycloak.AuthServices.Sdk/2.0.0-pre-1) | Provides integration with the [Keycloak Admin REST API](https://www.keycloak.org/docs-api/21.1.1/rest-api/), allowing you to manage users, roles, clients, and realms programmatically. Provides integration with the [Protection REST API](https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_protection_api) - a UMA-compliant set of endpoints. |
| Package | Description |
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Keycloak.AuthServices.Authentication](https://www.nuget.org/packages/Keycloak.AuthServices.Authentication) | As an OAuth2, OpenID Connect, and SAML compliant server, Keycloak can secure any application and service as long as the technology stack they are using supports any of these protocols. This library provides AspNetCore integration for JwtBearer and OpenIdConnect. |
| [Keycloak.AuthServices.Authorization](https://www.nuget.org/packages/Keycloak.AuthServices.Authorization) | Provides Role-Based Access Control (RBAC) and integration with the Keycloak Authorization Server. |
| [Keycloak.AuthServices.Sdk](https://www.nuget.org/packages/Keycloak.AuthServices.Sdk) | Provides integration with the [Keycloak Admin REST API](https://www.keycloak.org/docs-api/21.1.1/rest-api/), allowing you to manage users, groups, and realms programmatically. Provides integration with the [Protection REST API](https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_protection_api) - a UMA-compliant set of endpoints. |
| [Keycloak.AuthServices.Sdk.Kiota](https://www.nuget.org/packages/Keycloak.AuthServices.Sdk.Kiota) | Provides integration with the [Keycloak Admin REST API](https://www.keycloak.org/docs-api/21.1.1/rest-api/). The client is generated based on Open API Spec |
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task GetRealmAsyncKiota_RealmExists_Success()
var (services, configuration) = KeycloakSetup(AppSettings, testOutputHelper);
var tokenClientName = "keycloak_admin_api_token";

#region GetRealmAsync_RealmExists_Success
#region GetRealmAsyncKiota_RealmExists_Success
var options = configuration.GetKeycloakOptions<KeycloakAdminClientOptions>()!;

services.AddDistributedMemoryCache();
Expand Down Expand Up @@ -50,7 +50,7 @@ public async Task GetRealmAsyncKiota_RealmExists_Success()
realm.Should().NotBeNull();
realm!.Realm.Should().Be(realmName);

#endregion GetRealmAsync_RealmExists_Success
#endregion GetRealmAsyncKiota_RealmExists_Success

}
}

0 comments on commit 2e6378a

Please sign in to comment.