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
httpClientHttpClient
Methods
CreateChildGroupWithResponseAsync(string, string, GroupRepresentation, CancellationToken)
Set or create child.
public Task<HttpResponseMessage> CreateChildGroupWithResponseAsync(string realm, string groupId, GroupRepresentation group, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name (not ID).
groupIdstringGroup ID.
groupGroupRepresentationGroup representation.
cancellationTokenCancellationToken
Returns
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
realmstringRealm name (not ID).
groupGroupRepresentationGroup representation.
cancellationTokenCancellationToken
Returns
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
realmstringRealm name (not ID).
userUserRepresentationUser representation.
cancellationTokenCancellationToken
Returns
Remarks
Username must be unique.
DeleteCredentialWithResponseAsync(string, string, string, CancellationToken)
Remove a credential for a user
public Task<HttpResponseMessage> DeleteCredentialWithResponseAsync(string realm, string userId, string credentialId, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name(not ID).
userIdstringUser ID
credentialIdstringCredential ID
cancellationTokenCancellationToken
Returns
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
realmstringRealm name (not ID).
groupIdstringGroup ID.
cancellationTokenCancellationToken
Returns
DeleteUserWithResponseAsync(string, string, CancellationToken)
Delete the given user.
public Task<HttpResponseMessage> DeleteUserWithResponseAsync(string realm, string userId, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name (not ID).
userIdstringUser ID.
cancellationTokenCancellationToken
Returns
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
realmstringRealm name (not ID).
userIdstringUser ID.
requestExecuteActionsEmailRequestcancellationTokenCancellationToken
Returns
GetCredentialsWithResponseAsync(string, string, CancellationToken)
Get a user's credentials.
public Task<HttpResponseMessage> GetCredentialsWithResponseAsync(string realm, string userId, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name(not ID).
userIdstringUser ID
cancellationTokenCancellationToken
Returns
GetGroupWithResponseAsync(string, string, CancellationToken)
Get representation of a Group.
public Task<HttpResponseMessage> GetGroupWithResponseAsync(string realm, string groupId, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name (not ID).
groupIdstringGroup ID.
cancellationTokenCancellationToken
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
realmstringRealm name (not ID).
parametersGetGroupsRequestParametersOptional query parameters.
cancellationTokenCancellationToken
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
realmstringcancellationTokenCancellationToken
Returns
GetSubGroupsWithResponseAsync(string, string, GetGroupsRequestParameters?, CancellationToken)
Get a collection of sub groups by parent's id on the realm.
public Task<HttpResponseMessage> GetSubGroupsWithResponseAsync(string realm, string parentGroupId, GetGroupsRequestParameters? parameters = null, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name (not ID).
parentGroupIdstringParent Group ID.
parametersGetGroupsRequestParametersOptional query parameters.
cancellationTokenCancellationToken
Returns
GetUserCountWithResponseAsync(string, GetUserCountRequestParameters?, CancellationToken)
Get the integer amount of users on the realm that match the provided GetUserCountRequestParameters.
Note that the response is not JSON, but simply the integer value as a string.
public Task<HttpResponseMessage> GetUserCountWithResponseAsync(string realm, GetUserCountRequestParameters? parameters = null, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name (not ID).
parametersGetUserCountRequestParametersOptional query parameters.
cancellationTokenCancellationToken
Returns
- Task<HttpResponseMessage>
An integer amount of users
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
realmstringRealm name (not ID).
userIdstringUser ID.
parametersGetUserGroupsRequestParametersOptional query parameters.
cancellationTokenCancellationToken
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
realmstringRealm name (not ID).
userIdstringUser ID.
includeUserProfileMetadataboolIndicates if the user profile metadata should be added to the response.
cancellationTokenCancellationToken
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
realmstringRealm name (not ID).
parametersGetUsersRequestParametersOptional query parameters.
cancellationTokenCancellationToken
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
realmstringRealm name(not ID).
userIdstringUser ID.
groupIdstringGroup ID.
cancellationTokenCancellationToken
Returns
LeaveGroupWithResponseAsync(string, string, string, CancellationToken)
Leave a group
public Task<HttpResponseMessage> LeaveGroupWithResponseAsync(string realm, string userId, string groupId, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name(not ID).
userIdstringUser ID.
groupIdstringGroup ID.
cancellationTokenCancellationToken
Returns
ResetPasswordWithResponseAsync(string, string, CredentialRepresentation, CancellationToken)
Set up a new password for the user
public Task<HttpResponseMessage> ResetPasswordWithResponseAsync(string realm, string userId, CredentialRepresentation credential, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name(not ID).
userIdstringUser ID.
credentialCredentialRepresentationCredential representation.
cancellationTokenCancellationToken
Returns
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
realmstringRealm name (not ID).
userIdstringUser ID.
clientIdstringClient ID.
redirectUristringRedirect URI. The default for the redirect is the account client.
cancellationTokenCancellationToken
Returns
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
realmstringRealm name (not ID).
groupIdstringGroup ID.
groupGroupRepresentationGroup representation.
cancellationTokenCancellationToken
Returns
UpdateUserWithResponseAsync(string, string, UserRepresentation, CancellationToken)
Update the user.
public Task<HttpResponseMessage> UpdateUserWithResponseAsync(string realm, string userId, UserRepresentation user, CancellationToken cancellationToken = default)
Parameters
realmstringRealm name (not ID).
userIdstringUser ID.
userUserRepresentationUser representation.
cancellationTokenCancellationToken