Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keycloak SDK get Groups #49

Merged
merged 6 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ internal static class KeycloakClientApiConstants
internal const string SendVerifyEmail = $"{GetRealm}/users/{{id}}/send-verify-email";

internal const string ExecuteActionsEmail = $"{GetRealm}/users/{{id}}/execute-actions-email";
internal const string GetUserGroups = $"{GetRealm}/users/{{id}}/groups";



internal const string GetGroups = $"{GetRealm}/groups";

internal const string GetGroup = $"{GetRealm}/groups/{{id}}";

#endregion
}
2 changes: 1 addition & 1 deletion src/Keycloak.AuthServices.Sdk/Admin/IKeycloakClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Keycloak.AuthServices.Sdk.Admin;
/// Aggregates multiple clients. <see cref="IKeycloakRealmClient"/> and <see cref="IKeycloakProtectedResourceClient"/>
/// </remarks>
public interface IKeycloakClient
: IKeycloakRealmClient, IKeycloakProtectedResourceClient, IKeycloakUserClient
: IKeycloakRealmClient, IKeycloakProtectedResourceClient, IKeycloakUserClient, IKeycloakGroupClient
{
}
33 changes: 33 additions & 0 deletions src/Keycloak.AuthServices.Sdk/Admin/IKeycloakGroupClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Keycloak.AuthServices.Sdk.Admin;

using System.Threading.Tasks;
using Constants;
using Models;
using Refit;
using Requests.Groups;

/// <summary>
/// Group management
/// </summary>
[Headers("Accept: application/json")]
public interface IKeycloakGroupClient
{

/// <summary>
/// Get a stream of groups on the realm.
/// </summary>
/// <param name="realm">Realm name.</param>
/// <param name="parameters">Optional query parameters.</param>
/// <returns>A stream of groups, filtered according to query parameters.</returns>
[Get(KeycloakClientApiConstants.GetGroups)]
Task<IEnumerable<Group>> GetGroups(string realm, [Query] GetGroupRequestParameters? parameters = default);

/// <summary>
/// Get representation of a group.
/// </summary>
/// <param name="realm">Realm name.</param>
/// <param name="groupId">group ID.</param>
/// <returns>The group representation.</returns>
[Get(KeycloakClientApiConstants.GetGroup)]
Task<Group> GetGroup(string realm, [AliasAs("id")] string groupId);
}
11 changes: 11 additions & 0 deletions src/Keycloak.AuthServices.Sdk/Admin/IKeycloakUserClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Constants;
using Models;
using Refit;
using Requests.Groups;
using Requests.Users;

/// <summary>
Expand Down Expand Up @@ -84,4 +85,14 @@ Task ExecuteActionsEmail(string realm, [AliasAs("id")] string userId,
[Query] int? lifespan = default,
[Query][AliasAs("redirect_uri")] string? redirectUri = default,
[Body] List<string>? actions = default);

/// <summary>
/// Get a users's groups.
/// </summary>
/// <param name="realm">Realm name (not ID).</param>
/// <param name="userId">User ID.</param>
/// <param name="parameters">Optional query parameters.</param>
/// <returns>A stream of users, filtered according to query parameters.</returns>
[Get(KeycloakClientApiConstants.GetUserGroups)]
Task<IEnumerable<Group>> GetUserGroups(string realm, [AliasAs("id")] string userId, [Query] GetGroupRequestParameters? parameters = default);
}
18 changes: 18 additions & 0 deletions src/Keycloak.AuthServices.Sdk/Admin/Models/Group/Group.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma warning disable CS1591, CS8618
namespace Keycloak.AuthServices.Sdk.Admin.Models;

using System.Collections.Generic;

/// <summary>
/// Group representation.
/// </summary>
public class Group
{
public string Id { get; init; } = default!;
public string? Name { get; init; }
public string? Path { get; init; }
public Dictionary<string, string>? ClientRoles { get; init; }
public string[]? RealmRoles { get; init; }
public Group[]? SubGroups { get; init; }
public Dictionary<string, string[]>? Attributes { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
namespace Keycloak.AuthServices.Sdk.Admin.Requests.Groups;

using Keycloak.AuthServices.Sdk.Admin.Models;
using Refit;

/// <summary>
/// Optional request parameters for the <see cref="IKeycloakGoupClient.GetGroups"/> endpoint.

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'GetGroups' that could not be resolved

Check warning on line 7 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'GetGroups' that could not be resolved
/// It can be called in three different ways.
/// <list type="number">
/// <item>
/// <description>
/// Don’t specify any criteria. A stream of all groups within that realm will be returned (limited by pagination).
/// </description>
/// </item>
/// <item>
/// <description>
/// If <see cref="Search"/> is specified, other criteria such as <see cref="LastName"/>

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 17 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'LastName' that could not be resolved
/// will be ignored even though you may set them. The <see cref="Search"/> string will be matched against
/// the <see cref="User.FirstName"/>, <see cref="User.LastName"/>, <see cref="User.Username"/>
/// and the <see cref="User.Email"/> of a <see cref="User"/>.
/// </description>
/// </item>
/// <item>
/// <description>
/// If <see cref="Search"/> is unspecified but any of <see cref="LastName"/>, <see cref="FirstName"/>,

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'FirstName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'FirstName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'FirstName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'FirstName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 25 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'FirstName' that could not be resolved
/// <see cref="Email"/> or <see cref="Username"/> are specified, then those criteria are matched against

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'Email' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'Username' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'Email' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'Username' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'Email' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'Username' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'Email' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'Username' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'Email' that could not be resolved

Check warning on line 26 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-macOS-latest

XML comment has cref attribute 'Username' that could not be resolved
/// their respective fields on a <see cref="User"/> entity. Combined with a logical <c>AND</c>.
/// </description>
/// </item>
/// </list>
/// </summary>
public class GetGroupRequestParameters
{
/// <summary>
/// Defines whether brief representations are returned. Default is false.
/// </summary>
[AliasAs("briefRepresentation")]
public bool? BriefRepresentation { get; init; }

/// <summary>
/// Defines whether the params <see cref="LastName"/>, <see cref="FirstName"/>,

Check warning on line 41 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-ubuntu-latest

XML comment has cref attribute 'LastName' that could not be resolved

Check warning on line 41 in src/Keycloak.AuthServices.Sdk/Admin/Requests/Groups/GetGroupRequestParameters.cs

View workflow job for this annotation

GitHub Actions / Build-windows-latest

XML comment has cref attribute 'LastName' that could not be resolved
/// <see cref="Email"/> and <see cref="Username"/> must match exactly
/// </summary>
[AliasAs("exact")]
public bool? Exact { get; init; }

/// <summary>
/// Pagination offset.
/// </summary>
[AliasAs("first")]
public int? First { get; init; }

/// <summary>
/// Maximum results size. Default is 100.
/// </summary>
[AliasAs("max")]
public int? Max { get; init; }

/// <summary>
/// A query to search for custom attributes, in the format "<c>key1:value2 key2:value2</c>".
/// </summary>
[AliasAs("q")]
public string? Query { get; init; }

/// <summary>
/// Search for a string contained in <see cref="Username"/>, <see cref="FirstName"/>,
/// <see cref="LastName"/> or <see cref="Email"/>.
/// </summary>
[AliasAs("search")]
public string? Search { get; init; }
}
Loading