Table of Contents

Class KeycloakClient

Namespace
Keycloak.AuthServices.Sdk.Admin
Assembly
Keycloak.AuthServices.Sdk.dll

Represents a client for interacting with the Keycloak Admin API.

public class KeycloakClient : IKeycloakClient, IKeycloakRealmClient, IKeycloakUserClient, IKeycloakGroupClient
Inheritance
KeycloakClient
Implements
Inherited Members

Constructors

KeycloakClient(HttpClient)

Initializes a new instance of the KeycloakClient class.

public KeycloakClient(HttpClient httpClient)

Parameters

httpClient HttpClient

Methods

CreateChildGroupWithResponseAsync(string, string, GroupRepresentation, CancellationToken)

Set or create child.

public Task<HttpResponseMessage> CreateChildGroupWithResponseAsync(string realm, string groupId, GroupRepresentation group, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

groupId string

Group ID.

group GroupRepresentation

Group representation.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

Remarks

This will just set the parent if it exists. Create it and set the parent if the group doesn’t exist.

CreateGroupWithResponseAsync(string, GroupRepresentation, CancellationToken)

Create or add a top level realm groupSet or create child.

public Task<HttpResponseMessage> CreateGroupWithResponseAsync(string realm, GroupRepresentation group, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

group GroupRepresentation

Group representation.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

Remarks

This will update the group and set the parent if it exists. Create it and set the parent if the group doesn’t exist.

CreateUserWithResponseAsync(string, UserRepresentation, CancellationToken)

Create a new user.

public Task<HttpResponseMessage> CreateUserWithResponseAsync(string realm, UserRepresentation user, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

user UserRepresentation

User representation.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

Remarks

Username must be unique.

DeleteGroupWithResponseAsync(string, string, CancellationToken)

Delete a group. Note: the Keycloak documentation does not specify if this deletes subgroups.

public Task<HttpResponseMessage> DeleteGroupWithResponseAsync(string realm, string groupId, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

groupId string

Group ID.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

DeleteUserWithResponseAsync(string, string, CancellationToken)

Delete the given user.

public Task<HttpResponseMessage> DeleteUserWithResponseAsync(string realm, string userId, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

userId string

User ID.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

ExecuteActionsEmailWithResponseAsync(string, string, ExecuteActionsEmailRequest, CancellationToken)

Execute actions email for the user.

public Task<HttpResponseMessage> ExecuteActionsEmailWithResponseAsync(string realm, string userId, ExecuteActionsEmailRequest request, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

userId string

User ID.

request ExecuteActionsEmailRequest
cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

GetGroupWithResponseAsync(string, string, CancellationToken)

Get representation of a Group.

public Task<HttpResponseMessage> GetGroupWithResponseAsync(string realm, string groupId, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

groupId string

Group ID.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

The group representation.

GetGroupsWithResponseAsync(string, GetGroupsRequestParameters?, CancellationToken)

Get a collection of groups on the realm.

public Task<HttpResponseMessage> GetGroupsWithResponseAsync(string realm, GetGroupsRequestParameters? parameters = null, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

parameters GetGroupsRequestParameters

Optional query parameters.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

A stream of groups, filtered according to query parameters.

GetRealmWithResponseAsync(string, CancellationToken)

Get realm

public Task<HttpResponseMessage> GetRealmWithResponseAsync(string realm, CancellationToken cancellationToken = default)

Parameters

realm string
cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

GetUserGroupsWithResponseAsync(string, string, GetUserGroupsRequestParameters?, CancellationToken)

Get a users's groups.

public Task<HttpResponseMessage> GetUserGroupsWithResponseAsync(string realm, string userId, GetUserGroupsRequestParameters? parameters = null, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

userId string

User ID.

parameters GetUserGroupsRequestParameters

Optional query parameters.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

A stream of users, filtered according to query parameters.

GetUserWithResponseAsync(string, string, bool, CancellationToken)

Get representation of a user.

public Task<HttpResponseMessage> GetUserWithResponseAsync(string realm, string userId, bool includeUserProfileMetadata = false, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

userId string

User ID.

includeUserProfileMetadata bool

Indicates if the user profile metadata should be added to the response.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

The user representation.

GetUsersWithResponseAsync(string, GetUsersRequestParameters?, CancellationToken)

Get a stream of users on the realm.

public Task<HttpResponseMessage> GetUsersWithResponseAsync(string realm, GetUsersRequestParameters? parameters = null, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

parameters GetUsersRequestParameters

Optional query parameters.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

A stream of users, filtered according to query parameters.

JoinGroupWithResponseAsync(string, string, string, CancellationToken)

Join a group

public Task<HttpResponseMessage> JoinGroupWithResponseAsync(string realm, string userId, string groupId, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name(not ID).

userId string

User ID.

groupId string

Group ID.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

LeaveGroupWithResponseAsync(string, string, string, CancellationToken)

Leave a group

public Task<HttpResponseMessage> LeaveGroupWithResponseAsync(string realm, string userId, string groupId, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name(not ID).

userId string

User ID.

groupId string

Group ID.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

SendVerifyEmailWithResponseAsync(string, string, string?, string?, CancellationToken)

Send an email-verification email to the user.

public Task<HttpResponseMessage> SendVerifyEmailWithResponseAsync(string realm, string userId, string? clientId = null, string? redirectUri = null, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

userId string

User ID.

clientId string

Client ID.

redirectUri string

Redirect URI. The default for the redirect is the account client.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

Remarks

An email contains a link the user can click to verify their email address.

UpdateGroupWithResponseAsync(string, string, GroupRepresentation, CancellationToken)

Update group, ignores subgroups.

public Task<HttpResponseMessage> UpdateGroupWithResponseAsync(string realm, string groupId, GroupRepresentation group, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

groupId string

Group ID.

group GroupRepresentation

Group representation.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>

UpdateUserWithResponseAsync(string, string, UserRepresentation, CancellationToken)

Update the user.

public Task<HttpResponseMessage> UpdateUserWithResponseAsync(string realm, string userId, UserRepresentation user, CancellationToken cancellationToken = default)

Parameters

realm string

Realm name (not ID).

userId string

User ID.

user UserRepresentation

User representation.

cancellationToken CancellationToken

Returns

Task<HttpResponseMessage>