Skip to content

Conversation

busla
Copy link
Contributor

@busla busla commented Oct 8, 2025

Summary

This PR adds support for custom OAuth authorization parameters via the OPENID_AUTHORIZATION_PARAMS environment variable, enabling use cases like AWS Cognito's idp_identifier parameter for direct identity provider redirection.

Problem Statement

When using LibreChat with AWS Cognito as an OIDC provider, there was no way to add the idp_identifier parameter that Cognito supports to redirect users directly to a specific identity provider, bypassing the Cognito Hosted UI.

Solution

Added a new environment variable OPENID_AUTHORIZATION_PARAMS that accepts a JSON object of custom parameters to be added to the OAuth authorization request.

Changes Made:

  • api/strategies/openidStrategy.js: Override authorizationRequestParams() in CustomOpenIDStrategy to parse and apply custom parameters
  • .env.example: Add documentation for the new environment variable
  • api/strategies/openidStrategy.spec.js: Add comprehensive test suite with 12 test cases

Features:

  • ✅ Accepts JSON object via environment variable
  • ✅ Graceful error handling for invalid JSON
  • ✅ Type conversion for numeric and boolean values
  • ✅ Filters out null values
  • ✅ Debug logging for added parameters
  • ✅ Backward compatible (opt-in via env var)

Usage Example

For AWS Cognito with a specific identity provider:

OPENID_AUTHORIZATION_PARAMS='{"idp_identifier":"MyIdentityProvider"}'

For multiple parameters:

OPENID_AUTHORIZATION_PARAMS='{"idp_identifier":"Provider","prompt":"login","max_age":"3600"}'

Testing

Added 12 comprehensive test cases covering:

  • ✅ Single and multiple parameter support
  • ✅ Invalid JSON handling
  • ✅ Non-object value handling (strings, arrays)
  • ✅ Null value handling
  • ✅ Numeric and boolean value conversion
  • ✅ Empty object handling
  • ✅ Special character support
  • ✅ Absence of configuration
  • ✅ Coexistence with other OpenID config

All new tests pass. Pre-existing test failures are unrelated to this PR.

Related Issues

Resolves the need for custom OAuth parameters in OpenID authentication flow, particularly for AWS Cognito idp_identifier support.


🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

busla and others added 3 commits October 8, 2025 08:30
…ters

Add support for custom OAuth authorization parameters via the
OPENID_AUTHORIZATION_PARAMS environment variable. This enables
use cases like AWS Cognito's idp_identifier parameter for direct
provider redirection.

Changes:
- Add authorizationRequestParams override in CustomOpenIDStrategy
- Parse JSON config from OPENID_AUTHORIZATION_PARAMS env var
- Handle invalid JSON gracefully with error logging
- Add documentation to .env.example
- Add comprehensive test suite with 12 test cases

Tests verify:
- Single and multiple parameter support
- Invalid JSON handling
- Non-object value handling
- Null, numeric, and boolean value conversion
- Empty object and special character support

🤖 Generated with Claude Code
Co-Authored-By: Claude <[email protected]>
Removed the unused createMockParams helper function from the
OPENID_AUTHORIZATION_PARAMS test suite to resolve ESLint error
about unused variables.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@busla busla marked this pull request as ready for review October 8, 2025 22:35
@busla busla marked this pull request as draft October 9, 2025 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant