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
stringRealm name (not ID).
groupId
stringGroup ID.
group
GroupRepresentationGroup representation.
cancellationToken
CancellationToken
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
realm
stringRealm name (not ID).
group
GroupRepresentationGroup representation.
cancellationToken
CancellationToken
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
realm
stringRealm name (not ID).
user
UserRepresentationUser representation.
cancellationToken
CancellationToken
Returns
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
stringRealm name (not ID).
groupId
stringGroup ID.
cancellationToken
CancellationToken
Returns
DeleteUserWithResponseAsync(string, string, CancellationToken)
Delete the given user.
public Task<HttpResponseMessage> DeleteUserWithResponseAsync(string realm, string userId, CancellationToken cancellationToken = default)
Parameters
realm
stringRealm name (not ID).
userId
stringUser ID.
cancellationToken
CancellationToken
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
realm
stringRealm name (not ID).
userId
stringUser ID.
request
ExecuteActionsEmailRequestcancellationToken
CancellationToken
Returns
GetGroupWithResponseAsync(string, string, CancellationToken)
Get representation of a Group.
public Task<HttpResponseMessage> GetGroupWithResponseAsync(string realm, string groupId, CancellationToken cancellationToken = default)
Parameters
realm
stringRealm name (not ID).
groupId
stringGroup 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
stringRealm name (not ID).
parameters
GetGroupsRequestParametersOptional 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
stringcancellationToken
CancellationToken
Returns
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
stringRealm name (not ID).
userId
stringUser ID.
parameters
GetUserGroupsRequestParametersOptional 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
stringRealm name (not ID).
userId
stringUser ID.
includeUserProfileMetadata
boolIndicates 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
stringRealm name (not ID).
parameters
GetUsersRequestParametersOptional 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
stringRealm name(not ID).
userId
stringUser ID.
groupId
stringGroup ID.
cancellationToken
CancellationToken
Returns
LeaveGroupWithResponseAsync(string, string, string, CancellationToken)
Leave a group
public Task<HttpResponseMessage> LeaveGroupWithResponseAsync(string realm, string userId, string groupId, CancellationToken cancellationToken = default)
Parameters
realm
stringRealm name(not ID).
userId
stringUser ID.
groupId
stringGroup ID.
cancellationToken
CancellationToken
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
realm
stringRealm name (not ID).
userId
stringUser ID.
clientId
stringClient ID.
redirectUri
stringRedirect URI. The default for the redirect is the account client.
cancellationToken
CancellationToken
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
realm
stringRealm name (not ID).
groupId
stringGroup ID.
group
GroupRepresentationGroup representation.
cancellationToken
CancellationToken
Returns
UpdateUserWithResponseAsync(string, string, UserRepresentation, CancellationToken)
Update the user.
public Task<HttpResponseMessage> UpdateUserWithResponseAsync(string realm, string userId, UserRepresentation user, CancellationToken cancellationToken = default)
Parameters
realm
stringRealm name (not ID).
userId
stringUser ID.
user
UserRepresentationUser representation.
cancellationToken
CancellationToken