Skip to content

🔧 feat: Add Basic Token Exchange Method for Actions OAuth flow #7844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025

Conversation

danny-avila
Copy link
Owner

Summary

Closes #7840

I added support for handling a token_exchange_method parameter to enable OAuth token exchanges using either default POST or HTTP Basic authentication, enhancing the Actions OAuth flow.

  • Extended the Actions OAuth callback and creation logic to pass and store the token_exchange_method parameter.
  • Updated the TokenService to select the token exchange mechanism based on the new parameter, supporting both default_post and basic_auth_header strategies.
  • Modified access and refresh token retrieval to conditionally move client credentials to the basic auth header, as required by the token_exchange_method.
  • Improved documentation and parameter validation for new OAuth exchange options.

Change Type

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Testing

I tested this by registering actions with both token exchange methods, completing the OAuth flow, and verifying correct token storage and response.

To further validate, I recommend:

  • Setting up a mock OAuth server supporting both token exchange patterns.
  • Executing OAuth actions with each method and confirming token issuance in the expected format.
  • Reviewing server logs to ensure the chosen exchange method is used correctly.
  • Adding unit tests for the TokenService covering both exchange paths.

Test Configuration:

  • Manual endpoint testing with OAuth providers
  • Local environment with dummy secrets
  • librechat-data-provider dependency providing required enums

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

- Enhanced the OAuth callback and action creation processes to include the `token_exchange_method` parameter.
- Updated the `TokenService` to handle different token exchange methods, allowing for either 'default_post' or 'basic_auth_header' approaches.
- Improved the handling of access tokens and refresh tokens based on the specified exchange method.
@danny-avila danny-avila merged commit 1bd8745 into dev Jun 12, 2025
5 checks passed
@danny-avila danny-avila deleted the feat/oauth-basic-token-exchange branch June 12, 2025 02:12
jmaddington pushed a commit to jmaddington/LibreChat that referenced this pull request Jun 17, 2025
…-avila#7844)

- Enhanced the OAuth callback and action creation processes to include the `token_exchange_method` parameter.
- Updated the `TokenService` to handle different token exchange methods, allowing for either 'default_post' or 'basic_auth_header' approaches.
- Improved the handling of access tokens and refresh tokens based on the specified exchange method.
kridshanop added a commit to schoolkit-co/chat that referenced this pull request Jun 18, 2025
commit 0103b4b
Author: Danny Avila <[email protected]>
Date:   Fri Jun 13 18:17:25 2025 -0400

    🧹 chore: Cleanup base64 Handling for Azure Mistral OCR (danny-avila#7892)

    * 🧹 chore: Remove Comments and Cleanup base64 handling for Azure Mistral OCR

    * chore: Remove unnecessary await from MCP instructions formatting in AgentClient

    * ci: Update document_url regex in MistralOCR tests to support PDF format

commit 5eb0703
Author: richzw <[email protected]>
Date:   Sat Jun 14 05:51:02 2025 +0800

    🌐 fix: Support `global` location for Google VertexAI (danny-avila#7768)

    * fix: Check if loc is 'global' and set the endpoint prefix accordingly

    * fix: ESLint error

    ---------

    Co-authored-by: Danny Avila <[email protected]>

commit 4419e2c
Author: Danny Avila <[email protected]>
Date:   Fri Jun 13 15:47:41 2025 -0400

    ✨ feat: Agent Panel UI Enhancements (danny-avila#7800)

    * feat: add MCP Panel to Agent Builder

    - Add MCP server panel and configuration UI
    - Implement MCP input forms and tool lists
    - Add MCP icon and metadata support
    - Integrate MCP with agent configuration
    - Add localization support for MCP features
    - Refactor components for better reusability
    - Update types and add MCP-related mutations
    - Fix small issues with Actions and AgentSelect
    - Refactor AgentPanelSwitch and related components to use new
      AgentPanelContext to reduce prop drilling

    * chore: import order

    * chore: clean up import statements and unused var in ActionsPanel component

    * refactor: AgentPanelContext with actions query, remove unnecessary `actions` state

    - Added actions query using `useGetActionsQuery` to fetch actions based on the current agent ID.
    - Removed now unused `setActions` state and related logic from `AgentPanelContext` and `AgentPanelSwitch` components.
    - Updated `AgentPanelContextType` to reflect the removal of `setActions`.

    * chore: re-order import statements in AgentConfig component

    * chore: re-order import statements in ModelPanel component

    * chore: update ModelPanel props to consolidated props to avoid passing unnecessary props

    * chore: update import statements in Providers index file to include ToastProvider and AgentPanelContext exports

    * chore: clean up import statements in VersionPanel component

    * refactor: streamline AgentConfig and AgentPanel components

    - Consolidated props in AgentConfig to only include necessary fields.
    - Updated AgentPanel to remove unused state and props, enhancing clarity and maintainability.
    - Reorganized import statements for better structure and readability.

    * refactor: replace default agent form values with utility function

    - Updated AgentsProvider, AgentPanel, AgentSelect, and DeleteButton components to use getDefaultAgentFormValues utility function instead of directly importing defaultAgentFormValues.
    - Enhanced the initialization of agent forms by incorporating localStorage values for model and provider in the new utility function.

    * chore: comment out rendering MCPSection

    ---------

    Co-authored-by: Dustin Healy <[email protected]>

commit 5f2d1c5
Author: Danny Avila <[email protected]>
Date:   Fri Jun 13 15:14:57 2025 -0400

    👁️ feat: Azure Mistral OCR Strategy (danny-avila#7888)

    * 👁️ feat: Add Azure Mistral OCR strategy and endpoint integration

    This commit introduces a new OCR strategy named 'azure_mistral_ocr', allowing the use of a Mistral OCR endpoint deployed on Azure. The configuration, schemas, and file upload strategies have been updated to support this integration, enabling seamless OCR processing via Azure-hosted Mistral services.

    * 🗑️ chore: Clean up .gitignore by removing commented-out uncommon directory name

    * chore: remove unused vars

    * refactor: Move createAxiosInstance to packages/api/utils and update imports

    - Removed the createAxiosInstance function from the config module and relocated it to a new utils module for better organization.
    - Updated import paths in relevant files to reflect the new location of createAxiosInstance.
    - Added tests for createAxiosInstance to ensure proper functionality and proxy configuration handling.

    * chore: move axios helpers to packages/api

    - Added logAxiosError function to @librechat/api for centralized error logging.
    - Updated imports across various files to use the new logAxiosError function.
    - Removed the old axios.js utility file as it is no longer needed.

    * chore: Update Jest moduleNameMapper for improved path resolution

    - Added a new mapping for '~/' to resolve module paths in Jest configuration, enhancing import handling for the project.

    * feat: Implement Mistral OCR API integration in TS

    * chore: Update MistralOCR tests based on new imports

    * fix: Enhance MistralOCR configuration handling and tests

    - Introduced helper functions for resolving configuration values from environment variables or hardcoded settings.
    - Updated the uploadMistralOCR and uploadAzureMistralOCR functions to utilize the new configuration resolution logic.
    - Improved test cases to ensure correct behavior when mixing environment variables and hardcoded values.
    - Mocked file upload and signed URL responses in tests to validate functionality without external dependencies.

    * feat: Enhance MistralOCR functionality with improved configuration and error handling

    - Introduced helper functions for loading authentication configuration and resolving values from environment variables.
    - Updated uploadMistralOCR and uploadAzureMistralOCR functions to utilize the new configuration logic.
    - Added utility functions for processing OCR results and creating error messages.
    - Improved document type determination and result aggregation for better OCR processing.

    * refactor: Reorganize OCR type imports in Mistral CRUD file

    - Moved OCRResult, OCRResultPage, and OCRImage imports to a more logical grouping for better readability and maintainability.

    * feat: Add file exports to API and create files index

    * chore: Update OCR types for enhanced structure and clarity

    - Redesigned OCRImage interface to include mandatory fields and improved naming conventions.
    - Added PageDimensions interface for better representation of page metrics.
    - Updated OCRResultPage to include dimensions and mandatory images array.
    - Refined OCRResult to include document annotation and usage information.

    * refactor: use TS counterpart of uploadOCR methods

    * ci: Update MistralOCR tests to reflect new OCR result structure

    * chore: Bump version of @librechat/api to 1.2.3 in package.json and package-lock.json

    * chore: Update CONFIG_VERSION to 1.2.8

    * chore: remove unused sendEvent function from config module (now imported from '@librechat/api')

    * chore: remove MistralOCR service files and tests (now in '@librechat/api')

    * ci: update logger import in ModelService tests to use @librechat/data-schemas

    ---------

    Co-authored-by: arthurolivierfortin <[email protected]>

commit 46ff008
Author: Marco Beretta <[email protected]>
Date:   Thu Jun 12 23:34:04 2025 +0200

    🤖 refactor: Improve Speech Settings Initialization (danny-avila#7869)

    * ✨ feat: Implement speech settings initialization and update settings handling

    * 🔧 fix: Ensure setters reference is included in useEffect dependencies for speech settings initialization

    * chore: Update setter reference in useSpeechSettingsInit for improved type safety

    ---------

    Co-authored-by: Danny Avila <[email protected]>

commit 55f79bd
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Thu Jun 12 08:25:10 2025 -0400

    🌍 i18n: Update translation.json with latest translations (danny-avila#7727)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

commit 1bd8745
Author: Danny Avila <[email protected]>
Date:   Wed Jun 11 22:12:50 2025 -0400

    🔧 feat: Add Basic Token Exchange Method for Actions OAuth flow (danny-avila#7844)

    - Enhanced the OAuth callback and action creation processes to include the `token_exchange_method` parameter.
    - Updated the `TokenService` to handle different token exchange methods, allowing for either 'default_post' or 'basic_auth_header' approaches.
    - Improved the handling of access tokens and refresh tokens based on the specified exchange method.

commit 6488873
Author: Samuel Path <[email protected]>
Date:   Wed Jun 11 20:27:27 2025 +0200

    🔧 fix: Properly handle Token Expiry Defaults when Env Variable not set (danny-avila#7834)

commit 13c7ceb
Author: Danny Avila <[email protected]>
Date:   Wed Jun 11 14:17:48 2025 -0400

    📋 fix: Agent Resource Deduplication & Sharing Duplicate False Positive (danny-avila#7835)

    * fix: `primeResources` to Prevent Duplicate Files Across Sources

    - Added multiple test cases to ensure that the `primeResources` function correctly handles duplicate files from OCR and attachments, including scenarios with shared files, files without IDs, and duplicates within attachments.
    - Implemented logic to categorize files into appropriate tool resources while preventing duplicates across different categories.
    - Enhanced error handling and ensured that unique files are returned in the final attachments array.

    * fix: Update ToolService to handle single OCR tool case (no loaded tool necessary)

    * refactor: Add skipVersioning option to updateAgent for isolated updates

    - for now, mainly concerns sharing/unsharing of agents

    * chore: Update translation for shared agent message in UI

commit cdf42b3
Author: Danny Avila <[email protected]>
Date:   Tue Jun 10 22:20:41 2025 -0400

    ✨ feat: Add Dynamic User Field Placeholder Support in MCP Variables (danny-avila#7825)

    * chore: linting in mcp.spec.ts

    * chore: linting in mcp.ts

    * feat(mcp): support dynamic user field placeholders in MCP environment variables

    - Added user object handling in MCP options, allowing for dynamic user field processing in environment variables, headers, and URLs.
    - Updated `processMCPEnv` to utilize user fields for more flexible configurations.

    * chore: update backend review workflow to include unit tests for @librechat/data-schemas

commit c2a18f6
Author: Sebastien Bruel <[email protected]>
Date:   Wed Jun 11 11:12:13 2025 +0900

    ⏱️ refactor: Retry `/api/convos/gen_title` every 1s for up to 20s (danny-avila#7807)
kridshanop added a commit to schoolkit-co/chat that referenced this pull request Jun 20, 2025
commit 0103b4b
Author: Danny Avila <[email protected]>
Date:   Fri Jun 13 18:17:25 2025 -0400

    🧹 chore: Cleanup base64 Handling for Azure Mistral OCR (danny-avila#7892)

    * 🧹 chore: Remove Comments and Cleanup base64 handling for Azure Mistral OCR

    * chore: Remove unnecessary await from MCP instructions formatting in AgentClient

    * ci: Update document_url regex in MistralOCR tests to support PDF format

commit 5eb0703
Author: richzw <[email protected]>
Date:   Sat Jun 14 05:51:02 2025 +0800

    🌐 fix: Support `global` location for Google VertexAI (danny-avila#7768)

    * fix: Check if loc is 'global' and set the endpoint prefix accordingly

    * fix: ESLint error

    ---------

    Co-authored-by: Danny Avila <[email protected]>

commit 4419e2c
Author: Danny Avila <[email protected]>
Date:   Fri Jun 13 15:47:41 2025 -0400

    ✨ feat: Agent Panel UI Enhancements (danny-avila#7800)

    * feat: add MCP Panel to Agent Builder

    - Add MCP server panel and configuration UI
    - Implement MCP input forms and tool lists
    - Add MCP icon and metadata support
    - Integrate MCP with agent configuration
    - Add localization support for MCP features
    - Refactor components for better reusability
    - Update types and add MCP-related mutations
    - Fix small issues with Actions and AgentSelect
    - Refactor AgentPanelSwitch and related components to use new
      AgentPanelContext to reduce prop drilling

    * chore: import order

    * chore: clean up import statements and unused var in ActionsPanel component

    * refactor: AgentPanelContext with actions query, remove unnecessary `actions` state

    - Added actions query using `useGetActionsQuery` to fetch actions based on the current agent ID.
    - Removed now unused `setActions` state and related logic from `AgentPanelContext` and `AgentPanelSwitch` components.
    - Updated `AgentPanelContextType` to reflect the removal of `setActions`.

    * chore: re-order import statements in AgentConfig component

    * chore: re-order import statements in ModelPanel component

    * chore: update ModelPanel props to consolidated props to avoid passing unnecessary props

    * chore: update import statements in Providers index file to include ToastProvider and AgentPanelContext exports

    * chore: clean up import statements in VersionPanel component

    * refactor: streamline AgentConfig and AgentPanel components

    - Consolidated props in AgentConfig to only include necessary fields.
    - Updated AgentPanel to remove unused state and props, enhancing clarity and maintainability.
    - Reorganized import statements for better structure and readability.

    * refactor: replace default agent form values with utility function

    - Updated AgentsProvider, AgentPanel, AgentSelect, and DeleteButton components to use getDefaultAgentFormValues utility function instead of directly importing defaultAgentFormValues.
    - Enhanced the initialization of agent forms by incorporating localStorage values for model and provider in the new utility function.

    * chore: comment out rendering MCPSection

    ---------

    Co-authored-by: Dustin Healy <[email protected]>

commit 5f2d1c5
Author: Danny Avila <[email protected]>
Date:   Fri Jun 13 15:14:57 2025 -0400

    👁️ feat: Azure Mistral OCR Strategy (danny-avila#7888)

    * 👁️ feat: Add Azure Mistral OCR strategy and endpoint integration

    This commit introduces a new OCR strategy named 'azure_mistral_ocr', allowing the use of a Mistral OCR endpoint deployed on Azure. The configuration, schemas, and file upload strategies have been updated to support this integration, enabling seamless OCR processing via Azure-hosted Mistral services.

    * 🗑️ chore: Clean up .gitignore by removing commented-out uncommon directory name

    * chore: remove unused vars

    * refactor: Move createAxiosInstance to packages/api/utils and update imports

    - Removed the createAxiosInstance function from the config module and relocated it to a new utils module for better organization.
    - Updated import paths in relevant files to reflect the new location of createAxiosInstance.
    - Added tests for createAxiosInstance to ensure proper functionality and proxy configuration handling.

    * chore: move axios helpers to packages/api

    - Added logAxiosError function to @librechat/api for centralized error logging.
    - Updated imports across various files to use the new logAxiosError function.
    - Removed the old axios.js utility file as it is no longer needed.

    * chore: Update Jest moduleNameMapper for improved path resolution

    - Added a new mapping for '~/' to resolve module paths in Jest configuration, enhancing import handling for the project.

    * feat: Implement Mistral OCR API integration in TS

    * chore: Update MistralOCR tests based on new imports

    * fix: Enhance MistralOCR configuration handling and tests

    - Introduced helper functions for resolving configuration values from environment variables or hardcoded settings.
    - Updated the uploadMistralOCR and uploadAzureMistralOCR functions to utilize the new configuration resolution logic.
    - Improved test cases to ensure correct behavior when mixing environment variables and hardcoded values.
    - Mocked file upload and signed URL responses in tests to validate functionality without external dependencies.

    * feat: Enhance MistralOCR functionality with improved configuration and error handling

    - Introduced helper functions for loading authentication configuration and resolving values from environment variables.
    - Updated uploadMistralOCR and uploadAzureMistralOCR functions to utilize the new configuration logic.
    - Added utility functions for processing OCR results and creating error messages.
    - Improved document type determination and result aggregation for better OCR processing.

    * refactor: Reorganize OCR type imports in Mistral CRUD file

    - Moved OCRResult, OCRResultPage, and OCRImage imports to a more logical grouping for better readability and maintainability.

    * feat: Add file exports to API and create files index

    * chore: Update OCR types for enhanced structure and clarity

    - Redesigned OCRImage interface to include mandatory fields and improved naming conventions.
    - Added PageDimensions interface for better representation of page metrics.
    - Updated OCRResultPage to include dimensions and mandatory images array.
    - Refined OCRResult to include document annotation and usage information.

    * refactor: use TS counterpart of uploadOCR methods

    * ci: Update MistralOCR tests to reflect new OCR result structure

    * chore: Bump version of @librechat/api to 1.2.3 in package.json and package-lock.json

    * chore: Update CONFIG_VERSION to 1.2.8

    * chore: remove unused sendEvent function from config module (now imported from '@librechat/api')

    * chore: remove MistralOCR service files and tests (now in '@librechat/api')

    * ci: update logger import in ModelService tests to use @librechat/data-schemas

    ---------

    Co-authored-by: arthurolivierfortin <[email protected]>

commit 46ff008
Author: Marco Beretta <[email protected]>
Date:   Thu Jun 12 23:34:04 2025 +0200

    🤖 refactor: Improve Speech Settings Initialization (danny-avila#7869)

    * ✨ feat: Implement speech settings initialization and update settings handling

    * 🔧 fix: Ensure setters reference is included in useEffect dependencies for speech settings initialization

    * chore: Update setter reference in useSpeechSettingsInit for improved type safety

    ---------

    Co-authored-by: Danny Avila <[email protected]>

commit 55f79bd
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Thu Jun 12 08:25:10 2025 -0400

    🌍 i18n: Update translation.json with latest translations (danny-avila#7727)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

commit 1bd8745
Author: Danny Avila <[email protected]>
Date:   Wed Jun 11 22:12:50 2025 -0400

    🔧 feat: Add Basic Token Exchange Method for Actions OAuth flow (danny-avila#7844)

    - Enhanced the OAuth callback and action creation processes to include the `token_exchange_method` parameter.
    - Updated the `TokenService` to handle different token exchange methods, allowing for either 'default_post' or 'basic_auth_header' approaches.
    - Improved the handling of access tokens and refresh tokens based on the specified exchange method.

commit 6488873
Author: Samuel Path <[email protected]>
Date:   Wed Jun 11 20:27:27 2025 +0200

    🔧 fix: Properly handle Token Expiry Defaults when Env Variable not set (danny-avila#7834)

commit 13c7ceb
Author: Danny Avila <[email protected]>
Date:   Wed Jun 11 14:17:48 2025 -0400

    📋 fix: Agent Resource Deduplication & Sharing Duplicate False Positive (danny-avila#7835)

    * fix: `primeResources` to Prevent Duplicate Files Across Sources

    - Added multiple test cases to ensure that the `primeResources` function correctly handles duplicate files from OCR and attachments, including scenarios with shared files, files without IDs, and duplicates within attachments.
    - Implemented logic to categorize files into appropriate tool resources while preventing duplicates across different categories.
    - Enhanced error handling and ensured that unique files are returned in the final attachments array.

    * fix: Update ToolService to handle single OCR tool case (no loaded tool necessary)

    * refactor: Add skipVersioning option to updateAgent for isolated updates

    - for now, mainly concerns sharing/unsharing of agents

    * chore: Update translation for shared agent message in UI

commit cdf42b3
Author: Danny Avila <[email protected]>
Date:   Tue Jun 10 22:20:41 2025 -0400

    ✨ feat: Add Dynamic User Field Placeholder Support in MCP Variables (danny-avila#7825)

    * chore: linting in mcp.spec.ts

    * chore: linting in mcp.ts

    * feat(mcp): support dynamic user field placeholders in MCP environment variables

    - Added user object handling in MCP options, allowing for dynamic user field processing in environment variables, headers, and URLs.
    - Updated `processMCPEnv` to utilize user fields for more flexible configurations.

    * chore: update backend review workflow to include unit tests for @librechat/data-schemas

commit c2a18f6
Author: Sebastien Bruel <[email protected]>
Date:   Wed Jun 11 11:12:13 2025 +0900

    ⏱️ refactor: Retry `/api/convos/gen_title` every 1s for up to 20s (danny-avila#7807)
rhonyabdullah pushed a commit to rhonyabdullah/LibreChat that referenced this pull request Jun 27, 2025
…-avila#7844)

- Enhanced the OAuth callback and action creation processes to include the `token_exchange_method` parameter.
- Updated the `TokenService` to handle different token exchange methods, allowing for either 'default_post' or 'basic_auth_header' approaches.
- Improved the handling of access tokens and refresh tokens based on the specified exchange method.
kenshinsamue pushed a commit to intelequia/LibreChat that referenced this pull request Aug 4, 2025
…-avila#7844)

- Enhanced the OAuth callback and action creation processes to include the `token_exchange_method` parameter.
- Updated the `TokenService` to handle different token exchange methods, allowing for either 'default_post' or 'basic_auth_header' approaches.
- Improved the handling of access tokens and refresh tokens based on the specified exchange method.
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