Skip to content

fix: Use 'username' claim for user_id in IBM JWT#1284

Merged
edwinjosechittilappilly merged 1 commit into
mainfrom
fix-sub
Mar 26, 2026
Merged

fix: Use 'username' claim for user_id in IBM JWT#1284
edwinjosechittilappilly merged 1 commit into
mainfrom
fix-sub

Conversation

@edwinjosechittilappilly

Copy link
Copy Markdown
Collaborator

Replace use of the 'uid' claim with the 'username' claim when deriving user_id from IBM JWTs, and align user_id selection with email/name extraction. The change uses claims.get('username', sub) as the fallback to the subject (sub), making user_id consistent with the email and display name fields. Note: this also subtly changes behavior when a username key exists but is empty (it will now be used rather than falling back to sub).

Replace use of the 'uid' claim with the 'username' claim when deriving user_id from IBM JWTs, and align user_id selection with email/name extraction. The change uses claims.get('username', sub) as the fallback to the subject (sub), making user_id consistent with the email and display name fields. Note: this also subtly changes behavior when a username key exists but is empty (it will now be used rather than falling back to sub).
@edwinjosechittilappilly edwinjosechittilappilly changed the title fixUse 'username' claim for user_id in IBM JWT fix: Use 'username' claim for user_id in IBM JWT Mar 26, 2026
@github-actions github-actions Bot added the backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) label Mar 26, 2026
@edwinjosechittilappilly edwinjosechittilappilly marked this pull request as ready for review March 26, 2026 21:08
Copilot AI review requested due to automatic review settings March 26, 2026 21:08
@github-actions github-actions Bot added the bug 🔴 Something isn't working. label Mar 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates IBM AMS JWT claim parsing so user_id is derived from the username claim (with fallback to sub), aligning the user_id choice with how email and name are currently extracted.

Changes:

  • Switch user_id derivation from the uid claim to the username claim (with sub fallback).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/dependencies.py
Comment on lines +129 to 131
user_id = claims.get("username", sub)
email = claims.get("username", sub)
name = claims.get("display_name", claims.get("username", sub))

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

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

Using claims.get("username", sub) changes fallback semantics compared to the previous ... or sub: if the username claim exists but is an empty string, user_id becomes "" (and later if ibm_token and user_id: will treat it as missing and return unauthenticated) even though a valid sub exists. If the intent is to fall back to sub when username is missing or empty, use claims.get("username") or sub (and consider reusing the same normalized value for email/name to keep them consistent).

Suggested change
user_id = claims.get("username", sub)
email = claims.get("username", sub)
name = claims.get("display_name", claims.get("username", sub))
normalized_username = claims.get("username") or sub
user_id = normalized_username
email = normalized_username
name = claims.get("display_name") or normalized_username

Copilot uses AI. Check for mistakes.
@github-actions github-actions Bot added the lgtm label Mar 26, 2026
@edwinjosechittilappilly edwinjosechittilappilly merged commit 19a51f4 into main Mar 26, 2026
19 checks passed
@github-actions github-actions Bot deleted the fix-sub branch March 26, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants