Skip to content

Add custom_attributes field to OrganizationMembership#82

Open
ajworkos wants to merge 2 commits intomainfrom
feature/add-idp-attributes-to-org-membership
Open

Add custom_attributes field to OrganizationMembership#82
ajworkos wants to merge 2 commits intomainfrom
feature/add-idp-attributes-to-org-membership

Conversation

@ajworkos
Copy link

@ajworkos ajworkos commented Feb 1, 2026

Summary

Adds custom_attributes field to OrganizationMembership model to expose custom attributes from identity providers.

Changes

  • Added custom_attributes field to OrganizationMembership type/model
  • Field type: Record/Map/Dictionary of string keys to any values
  • Always present, defaults to empty object {}
  • Updated fixtures and tests

API Field Details

The field will be present in:

  • REST API responses
  • Webhook events
  • Events API responses

JSON field name: custom_attributes (snake_case)

- Add idp_attributes: map() to type spec
- Add :idp_attributes to defstruct
- Add idp_attributes: map["idp_attributes"] || %{} to cast/1 with default empty map
- CI will run tests (local testing was not possible due to dependency issues)

This change adds support for IDP custom attributes on organization
memberships, which are sourced from the identity provider and stored
as customAttributes in the API.

Related to workos/workos PR #50470

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@greptile-apps
Copy link

greptile-apps bot commented Feb 1, 2026

Greptile Overview

Greptile Summary

Adds an idp_attributes field to WorkOS.UserManagement.OrganizationMembership (type + struct) and populates it during cast/1, defaulting to an empty map when absent.

Main concern: the PR description indicates the source is organizationMembership.customAttributes, but the code currently reads "idp_attributes" from the decoded map; if the API payload key differs (e.g., custom_attributes), the value will be dropped and always default to %{}.

Confidence Score: 3/5

  • This PR is likely safe to merge, but there is a realistic risk the new field won’t populate due to an API key mismatch.
  • Change is small and localized (type/struct + cast). The main risk is correctness: if the API provides customAttributes/custom_attributes as described, reading idp_attributes will silently default to %{} and lose data, which is hard to detect via types/tests unless fixtures cover it.
  • lib/workos/user_management/organization_membership.ex

Important Files Changed

Filename Overview
lib/workos/user_management/organization_membership.ex Adds idp_attributes field to OrganizationMembership type/struct and casts it from the API map with a default empty map.

Sequence Diagram

sequenceDiagram
  participant API as WorkOS API
  participant UM as WorkOS.UserManagement.OrganizationMembership
  participant Caller as SDK consumer

  API-->>UM: JSON map (decoded)
  UM->>UM: cast(map)
  UM->>UM: idp_attributes = map["idp_attributes"] || %{}
  UM-->>Caller: %OrganizationMembership{... idp_attributes: ...}
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@ajworkos ajworkos changed the title Add idp_attributes field to OrganizationMembership Add custom_attributes field to OrganizationMembership Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant