[PR #22744] feat: oauth refresh token #30041

Closed
opened 2026-02-21 20:46:44 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/22744

State: closed
Merged: Yes


… builtin tool provider

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This pull request introduces support for handling OAuth credential expiration by adding an expires_at field across multiple layers of the application. Key changes include updates to database models, migrations, API responses, and service logic.

Database and Model Updates:

API Enhancements:

Service Logic Updates:

  • api/services/tools/builtin_tools_manage_service.py:
    • Introduced a __DEFAULT_EXPIRES_AT__ constant for default expiration values.
    • Updated the add_builtin_tool_provider method to accept an optional expires_at parameter, defaulting to __DEFAULT_EXPIRES_AT__ if not provided [1] [2].

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/22744 **State:** closed **Merged:** Yes --- … builtin tool provider > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This pull request introduces support for handling OAuth credential expiration by adding an `expires_at` field across multiple layers of the application. Key changes include updates to database models, migrations, API responses, and service logic. ### Database and Model Updates: * [`api/models/tools.py`](diffhunk://#diff-47da0dde345f3d75da0ec954f50e3596e11aeb43189d781ca18b011babdf6b25R96): Added an `expires_at` column to the `BuiltinToolProvider` model with a default value of `2147483647`. * [`api/migrations/versions/2025_07_22_0019-375fe79ead14_oauth_refresh_token.py`](diffhunk://#diff-789fb9643efdea06eeaeed2ddd575e6dad8cbe64a481f9bfd54831063f20ecbcR1-R34): Created a migration to add the `expires_at` column to the `tool_builtin_providers` table with the same default value. ### API Enhancements: * [`api/core/plugin/entities/plugin_daemon.py`](diffhunk://#diff-46e08d911e881e86fffa12164a9892a9ed9e599fc36075f90eab057b3d8d2833R185-R188): Updated the `PluginOAuthCredentialsResponse` model to include `metadata` and `expires_at` fields for better OAuth credential representation. * [`api/controllers/console/workspace/tool_providers.py`](diffhunk://#diff-ad9645f98136bcb2c16a80b7a652b5d94ade5244bbdeaa492be5bea555bd1322R762): Added the `expires_at` field when creating OAuth credentials in the `get` method. ### Service Logic Updates: * `api/services/tools/builtin_tools_manage_service.py`: - Introduced a `__DEFAULT_EXPIRES_AT__` constant for default expiration values. - Updated the `add_builtin_tool_provider` method to accept an optional `expires_at` parameter, defaulting to `__DEFAULT_EXPIRES_AT__` if not provided [[1]](diffhunk://#diff-ef2c34db030a36a74232a4dce4d1c934387ba68dfe40f8860603ef2a75e99288R217) [[2]](diffhunk://#diff-ef2c34db030a36a74232a4dce4d1c934387ba68dfe40f8860603ef2a75e99288R274-R276). ## Screenshots | Before | After | |--------|-------| | ... | ... | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:46:44 -05:00
yindo closed this issue 2026-02-21 20:46:44 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30041