feat: Add OIDC group sync for Keycloak and generic OpenID providers #10015
+1,171
−6
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.
Pull Request: OIDC Group Synchronization for Keycloak and Generic OpenID Providers
Summary
Implements JWT token-based group synchronization to enable the granular permissions system with any OIDC provider (Keycloak, Auth0, Okta, etc.)
This PR addresses the need for non-Microsoft OIDC providers to utilize LibreChat's granular permissions system introduced in v0.7.9. Currently, group discovery only works with Microsoft Entra ID via Graph API. This implementation allows any OIDC provider to sync groups/roles from JWT tokens.
Related to #10006
Features:
Changes:
api/utils/extractJwtClaims.js
)syncUserOidcGroupsFromToken
in PermissionServiceidOnTheSource
to usesub
as fallback for non-Microsoft providers (Keycloak compatibility)'oidc'
as valid group source in schemaapi/utils/extractJwtClaims.spec.js
- JWT claim extraction testsapi/server/services/PermissionService.oidc.spec.js
- Service sync logic tests.env.example
Configuration Example:
Future Improvements (noted in code comments):
Change Type
Testing
Test Configuration:
OPENID_REUSE_TOKENS=true
OPENID_SYNC_GROUPS_FROM_TOKEN=true
OPENID_GROUPS_CLAIM_PATH=realm_access.roles
OPENID_GROUPS_TOKEN_KIND=access
OPENID_GROUP_SOURCE=keycloak
Test Process:
leonine
,default-roles-mediawan
,access_leonine
Test Results:
✅ Realm roles tested and working:
sub
claim (Keycloak) instead ofoid
(Microsoft-specific)📝 Keycloak groups (via group mapper) not yet tested but should work:
Unit Test Coverage:
Checklist
Documentation PR
Documentation has been submitted to the docs repository:
📝 LibreChat-AI/librechat.ai#426
Additional Context
This implementation follows the same pattern as the existing Entra ID group sync but reads from JWT claims instead of making Graph API calls, making it more efficient and compatible with any OIDC provider.
Benefits:
Tested with: Keycloak 26.x (realm roles confirmed working)
Compatible with: Any OIDC provider that includes groups/roles in JWT tokens
AI-slop-Disclaimer:
To my best knowledge I've reviewed and guided the development of this feature. However I seek maintainer's guidance as this code is heavily developed by cursor.