Skip to content

Commit

Permalink
accessing realm groups
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwinbobde committed Oct 23, 2023
1 parent 6d20ce5 commit 892d66e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ internal static class KeycloakClientApiConstants

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



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
{
}
34 changes: 34 additions & 0 deletions src/Keycloak.AuthServices.Sdk/Admin/IKeycloakGroupClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Keycloak.AuthServices.Sdk.Admin;

using System.Collections;
using System.Threading.Tasks;
using Constants;
using Models;
using Refit;
using Requests.Users;

/// <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 (not ID).</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] GetUsersRequestParameters? parameters = default);

/// <summary>
/// Get representation of a group.
/// </summary>
/// <param name="realm">Realm name (not ID).</param>
/// <param name="groupId">group ID.</param>
/// <returns>The group representation.</returns>
[Get(KeycloakClientApiConstants.GetGroups)]
Task<Group> GetGroups(string realm, [AliasAs("id")] string groupId);
}
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; }
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
Expand Up @@ -32,4 +32,8 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<Folder Include="Admin\Requests\Groups\" />
</ItemGroup>

</Project>

0 comments on commit 892d66e

Please sign in to comment.