Skip to content

Add organization member management APIs#23

Open
PatriQ94 wants to merge 1 commit intoBlack-Cockpit:masterfrom
PatriQ94:feature/add_org_member_management
Open

Add organization member management APIs#23
PatriQ94 wants to merge 1 commit intoBlack-Cockpit:masterfrom
PatriQ94:feature/add_org_member_management

Conversation

@PatriQ94
Copy link
Copy Markdown

@PatriQ94 PatriQ94 commented Apr 3, 2026

Summary

This PR adds organization member management endpoints to the IKcOrganizations API and fixes a serialization bug in the organization models that prevents organization operations from working against Keycloak 26+.

Bug Fix

KcOrganization and KcOrganizationDomain models used System.Text.Json attributes ([JsonPropertyName]), but the HTTP client base serializes request bodies with Newtonsoft.Json (JsonConvert.SerializeObject), which ignores those attributes. This caused property names to serialize as PascalCase (e.g., "Name" instead of "name"), resulting in 400 Bad Request from Keycloak:

Invalid json representation for OrganizationRepresentation. Unrecognized field "Name"

Fixed by switching the two organization model files to use [JsonProperty] from Newtonsoft.Json, consistent with all other models in the library.

New Features

Added 9 organization member management methods to IKcOrganizations:

Method HTTP Endpoint
AddMemberAsync POST /{realm}/organizations/{id}/members
GetMembersAsync GET /{realm}/organizations/{id}/members
GetMembersCountAsync GET /{realm}/organizations/{id}/members/count
GetMemberAsync GET /{realm}/organizations/{id}/members/{memberId}
RemoveMemberAsync DELETE /{realm}/organizations/{id}/members/{memberId}
GetMemberOrganizationsAsync GET /{realm}/organizations/{id}/members/{memberId}/organizations
GetUserOrganizationsAsync GET /{realm}/organizations/members/{userId}/organizations
InviteExistingUserAsync POST /{realm}/organizations/{id}/members/invite-existing-user
InviteUserAsync POST /{realm}/organizations/{id}/members/invite-user

Added KcOrganizationMemberFilter model for paginated member queries (supports first, max, search, exact, membershipType).

Files Changed

  • KcOrganization.cs, KcOrganizationDomain.cs[JsonPropertyName][JsonProperty] (bug fix)
  • IKcOrganizations.cs — 9 new method signatures
  • KcOrganizations.cs — 9 new method implementations
  • KcOrganizationMemberFilter.cs — new filter model
  • KcOrganizationMemberHappyPathTests.cs — integration tests covering the full member lifecycle

Testing

All 21 organization tests pass against Keycloak 26.5.1 (existing 10 + new 11, with InviteExistingUser skipped when SMTP is not configured).

@PatriQ94
Copy link
Copy Markdown
Author

PatriQ94 commented Apr 3, 2026

@hasnimehdi91 Review please 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant