OAuth Authorize Example
This guide teaches you how to build OAuth support into your tool plugin. OAuth is a better way to authorize tool plugins that need to access user data from third-party services, like Gmail or GitHub. Instead of requiring the user to manually enter API keys, OAuth lets the tool act on behalf of the user with their explicit consent.

Background

OAuth in Intellos involves two separate flows that developers should understand and design for.

Flow 1: OAuth Client Setup (Admin / Developer Flow)

Intellos instance’s admins or developers first need to register an OAuth app at the third-party service as a trusted application. From this, they’ll be able to obtain the necessary credentials to configure the Intellos tool provider as an OAuth client. As an example, here are the steps to setting up an OAuth client for Intellos’s Gmail tool provider:
  1. Go to Google Cloud Console and create a new project, or select existing one
  2. Enable the required APIs (e.g., Gmail API)
  1. Go to APIs & Services > Credentials
  2. Click Create Credentials > OAuth 2.0 Client IDs
  3. Choose Web application type
  4. Aclient_id and aclient_secret will be generated. Save these as the credentials.
Enter the client_id and client_secret on the OAuth Client configuration popup to set up the tool provider as a client.
OAuth Client Settings Dialog
Register the redirect URI generated by Intellos on the Google OAuth Client’s page:
OAuth Google Redirect URI
Intellos displays the redirect_uri in the OAuth Client configuration popup. It usually follows the format:
For self-hosted Intellos, the your-dify-domain should be consistent with the CONSOLE_WEB_URL.
Each service has unique requirements, so always consult the specific OAuth documentation for the services you’re integrating with.

Flow 2: User Authorization (Intellos User Flow)

After configuring OAuth clients, individual Intellos users can now authorize your plugin to access their personal accounts.
OAuth User Authorization

Implementation

1. Define OAuth Schema in Provider Manifest

The oauth_schema section of the provider manifest definitions tells Intellos what credentials your plugin OAuth needs and what the OAuth flow will produce. Two schemas are required for setting up OAuth:

client_schema

Defines the input for OAuth client setup:
gmail.yaml
The url field links directly to help documentations for the third-party service. This helps confused admins / developers.

credentials_schema

Specifies what the user authorization flow produces (Intellos manages these automatically):
Include both oauth_schema and credentials_for_provider to offer OAuth + API key auth options.

2. Complete Required OAuth Methods in Tool Provider

Add these imports to where your ToolProvider is implemented:
Your ToolProvider class must implement these three OAuth methods (taking GmailProvider as an example):
Under no circumstances should the client_secret be returned in the credentials of ToolOAuthCredentials, as this could lead to security issues.

3. Access Tokens in Your Tools

You may use OAuth credentials to make authenticated API calls in your Tool implementation like so:
self.runtime.credentials automatically provides the current user’s tokens. Intellos handles refresh automatically. For plugins that support both OAuth and API_KEY authentication, you can use self.runtime.credential_type to differentiate between the two authentication types.

4. Specify the Correct Versions

OAuth requires a recent SDK and Intellos version. Pin the plugin SDK in requirements.txt:
In manifest.yaml, add the minimum Intellos version:

Edit this page | Report an issue