fix(openid): distinguish ID tokens from access tokens in federated auth#62
fix(openid): distinguish ID tokens from access tokens in federated auth#62
Conversation
Fix OpenID Connect token handling to properly distinguish ID tokens from access tokens. ID tokens and access tokens are now stored and propagated separately, preventing token placeholders from resolving to identical values. - AuthService.js: Added idToken field to session storage - openIdJwtStrategy.js: Updated to read idToken from session - openidStrategy.js: Explicitly included id_token in federatedTokens - Test suites: Added comprehensive test coverage for token distinction Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe changes add id_token (OpenID Connect identity token) support across the authentication pipeline, enabling storage, propagation, and extraction of identity tokens alongside existing access and refresh tokens in OpenID flows. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip We've launched Issue Planner and it is currently in beta. Please try it out and share your feedback on Discord! Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/server/services/AuthService.js (1)
452-473:⚠️ Potential issue | 🟡 Minor
idTokenis not persisted in the cookie fallback path.When
req.sessionis unavailable (lines 459–472),idTokenis not stored in a cookie, so downstream consumers (e.g.,openIdJwtStrategy.js) will never see anid_tokenfor cookie-based sessions. If this is intentional—since ID tokens can be large and the cookie path is a legacy fallback—a brief comment explaining the omission would help future readers. If it's unintentional, it's a gap that breaks the feature for cookie-fallback users.
|
Recreating as a PR against upstream (danny-avila/LibreChat) |
What
Fix OpenID Connect token handling to properly distinguish ID tokens from access tokens. ID tokens and access tokens are now stored and propagated separately, preventing
LIBRECHAT_OPENID_ID_TOKENandLIBRECHAT_OPENID_ACCESS_TOKENplaceholders from resolving to identical values.Why
Previously, ID tokens were not stored separately from access tokens in the authentication flow. This caused both token types to resolve to the same value when used in placeholder substitution, breaking token propagation in MCP configurations and HTTP headers that require distinct ID and access tokens.
Changes
idTokenfield to session storage alongsideaccessTokenidTokenfrom session and use it infederatedTokensid_tokenfrom tokenset infederatedTokensobjectfederatedTokensLIBRECHAT_OPENID_ID_TOKENandLIBRECHAT_OPENID_ACCESS_TOKENresolve to different valuesTesting
Generated with Claude Code
Summary by CodeRabbit
New Features
Tests