Skip to content

feat: expose user picture and token attributes - #67

Merged
mainick merged 1 commit into
mainfrom
feature/user-picture-and-attributes
Nov 13, 2026
Merged

mainick merged 1 commit into
mainfrom
feature/user-picture-and-attributes

Conversation

@mainick

@mainick mainick commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Summary

Two additive read accessors for data Keycloak already puts in the token.

 UserRepresentationDTO::fromArray($claims)
   ...
   scope: ...
+  picture: $claims['picture'] ?? $claims['attributes']['picture'] ?? null

 KeycloakResourceOwner
   getRoles() / getGroups() / getScope()
+  getAttributes(): array<string,mixed>   // the `attributes` claim, [] when absent
+  getAttribute(string $name): ?string    // one attribute, null when absent

picture is the last constructor argument and defaults to null, so existing new UserRepresentationDTO(...) calls keep working.

Evidence

  • Before (main): tests/DTO/UserRepresentationDTOTest.php and tests/Token/KeycloakResourceOwnerTest.php fail. $dto->picture is an undefined property, and getAttributes()/getAttribute() are undefined methods.
  • After: vendor/bin/phpunit → OK (121 tests, 851 assertions) on PHP 8.4. The new tests cover: picture from the standard claim, the fallback to the user attribute, null when missing, the attributes claim, and the missing claim and missing key.

Merge Danger

Door: two-way

Additions only: nothing is removed or renamed. Reverting the PR removes the accessors.

Blast Radius: minimal

The only consumers that change are those that start calling the new accessors. Subclasses of KeycloakResourceOwner that already define getAttributes()/getAttribute() with a different signature would conflict.

🤖 Generated with Claude Code

- UserRepresentationDTO gets an optional `picture`, read from the standard
  `picture` claim with a fallback to the `picture` user attribute.
- KeycloakResourceOwner gets getAttributes() and getAttribute(), reading the
  `attributes` claim (e.g. a custom `agency_id` mapper).

Both additions are backward compatible: `picture` defaults to null and is
the last constructor argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mainick
mainick requested a balanced review from Copilot November 13, 2026 13:43
@mainick
mainick removed the request for review from Copilot November 13, 2026 13:43
@mainick mainick self-assigned this Nov 13, 2026
@mainick mainick added the enhancement New feature or request label Nov 13, 2026
@mainick mainick removed their assignment Nov 13, 2026

@mainick mainick left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

test

@mainick
mainick merged commit 93aacba into main Nov 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant