feat: expose keycloak global_id on the users/me serializer - #3666
Open
ChristopherChudzicki wants to merge 3 commits into
Open
feat: expose keycloak global_id on the users/me serializer#3666ChristopherChudzicki wants to merge 3 commits into
ChristopherChudzicki wants to merge 3 commits into
Conversation
OpenAPI Changes6 changes: 0 error, 0 warning, 6 info Unexpected changes? Ensure your branch is up-to-date with |
Contributor
There was a problem hiding this comment.
Pull request overview
Exposes the Keycloak-supplied stable user identifier (global_id) on the UserSerializer used by GET /api/v0/users/me/, and propagates the change through the OpenAPI spec and generated TypeScript client.
Changes:
- Added
global_idtoprofiles.serializers.UserSerializer(read-only) and updatedprofiles/views_test.pyexpectations. - Regenerated
openapi/specs/v0.yamland the generated TS client soUser.global_idis available asstring | null. - Updated the frontend
Usertest factory and adjusteddrf_lint_baseline.jsonline references.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| profiles/views_test.py | Updates API response assertions to include global_id for staff detail and /users/me (authed + anonymous). |
| profiles/serializers.py | Adds global_id to UserSerializer fields and marks it read-only. |
| openapi/specs/v0.yaml | Updates OpenAPI schema for User to include nullable, read-only global_id and regenerates required list. |
| frontends/api/src/test-utils/factories/user.ts | Updates TS test factory to populate global_id for authed users and include null for anonymous user objects. |
| frontends/api/src/generated/v0/api.ts | Regenerates TS types so User includes `global_id: string |
| drf_lint_baseline.json | Shifts baseline line numbers for pre-existing findings due to serializer changes. |
Add the Keycloak-supplied user UUID to the UserSerializer response so the frontend can identify the authenticated user by their SSO id. Uses the `global_id` field name to match how mitxonline already exposes the same value. Read-only and nullable: authenticated users get their global_id, anonymous users get null. Regenerated the OpenAPI spec and TypeScript client, and updated the user test factory for the new required field. Toward mitodl/hq#11158 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The exact-dict assertions in profiles/serializers_test.py omitted the new global_id key and were failing. Caught in PR review. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
test_list_users and test_patch_user also assert the exact serialized user shape; add the new global_id key. Caught by CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ChristopherChudzicki
force-pushed
the
cc/users-me-global-id
branch
from
July 24, 2026 19:36
428f95f to
ef35240
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What are the relevant tickets?
Toward https://github.com/mitodl/hq/issues/11158 (frontend needs a stable Keycloak-supplied user id; this exposes it via the API).
Description (What does it do?)
Adds the Keycloak-supplied user UUID to the
UserSerializerresponse used byGET /api/v0/users/me/, so the frontend can identify the authenticated user by their SSO id.global_idto match how mitxonline already exposes the same value (users.User.global_id, documented there as "the SSO ID for the user, usually the Keycloak ID"). Same field already exists on mit-learn'sUsermodel.global_id; anonymous users getnull(a stable key rather than an omitted one).v0.yaml) and the TypeScript client —Usernow hasglobal_id: string | null.usertest factory for the new required field.drf_lint_baseline.json(pre-existing ORM violations shifted down by the added serializer line — not new findings).How can this be tested?
GET /api/v0/users/me/should return aglobal_idmatching the user's Keycloak id. Make the same request while logged out and confirm the response contains"global_id": null.Additional Context
The
global_idkey is present asnullfor anonymous users, whereas the existing authed-only fields (first_name,profile, …) are omitted entirely. This falls out of DRF's handling of a nullable read-only field, and an always-present key is arguably friendlier for the frontend — flagging in case a reviewer prefers it omitted for anonymous.