Skip to main content
ODAI connects to third-party services on behalf of the user through OAuth 2.0. After completing a flow, ODAI stores the resulting tokens securely and uses them automatically when the relevant agent is invoked.

Supported services

ServiceCapabilitiesProtocol
Google (Gmail, Calendar, Docs, Drive)Email, events, documents, spreadsheets, presentationsOAuth 2.0
PlaidBank account balances and transactionsOAuth 2.0 (via Plaid Link)

Google OAuth flow

Connecting a Google account grants ODAI access to Gmail, Google Calendar, Google Docs, Google Drive, Sheets, and Slides.

Permissions requested

ODAI requests the following Google OAuth scopes:
ScopePurpose
userinfo.emailIdentify the Google account
userinfo.profileRetrieve the user’s name and profile picture
calendar.events.ownedRead and write calendar events
gmail.sendSend emails
gmail.modifyRead, label, and manage email
documentsRead and write Google Docs
docsGoogle Docs API access
driveRead and manage Google Drive files
spreadsheets.readonlyRead Google Sheets
presentations.readonlyRead Google Slides

Step 1: Initiate the flow

Send a POST request to /google_access_request with your Firebase ID token and the Google account email you want to connect:
POST /google_access_request HTTP/1.1
Authorization: <firebase-id-token>
Content-Type: application/x-www-form-urlencoded

[email protected]
The server validates your token and prepares an OAuth state parameter tied to your user account.

Step 2: Redirect to Google

Navigate your user to GET /auth/google/login with your Firebase ID token:
GET /auth/google/login?token=<firebase-id-token> HTTP/1.1
The server redirects to Google’s OAuth consent page where the user grants the requested permissions.

Step 3: Callback and token storage

After the user approves, Google redirects to /auth/google/callback. The server:
  1. Exchanges the authorization code for an access token and refresh token
  2. Retrieves the Google account’s email, name, and profile picture
  3. Encrypts the token with the user’s KMS key
  4. Stores the encrypted token in Firestore
  5. Marks the user’s account as connected to Google
  6. Redirects the user to the original redirect_uri
You can connect multiple Google accounts. Each account is stored separately and identified by its email address. The first account connected becomes the default.

Token refresh

Google OAuth tokens are refreshed automatically when they expire. ODAI stores the refresh_token alongside the access token, so re-authentication is not required unless the user revokes access through their Google account settings.

Disconnecting Google

To disconnect a Google account, the integration status is set to false in the user’s Firestore document. The stored tokens are cleared as part of this operation.

Plaid flow

Connecting a bank account through Plaid gives ODAI read access to account balances and transaction history.

Permissions requested

ODAI requests the following Plaid products:
ProductPurpose
transactionsTransaction history
authAccount and routing numbers
Send a POST request to /auth/plaid/create_link_token with your Firebase ID token:
POST /auth/plaid/create_link_token HTTP/1.1
Authorization: <firebase-id-token>
The response contains a link_token from Plaid:
{
  "link_token": "link-sandbox-...",
  "expiration": "2025-01-01T00:00:00Z",
  "request_id": "..."
}
Use the link_token to initialize Plaid Link in your frontend. Plaid handles the bank selection and credential entry. On success, Plaid returns a public_token.
const handler = Plaid.create({
  token: linkToken,
  onSuccess: (publicToken, metadata) => {
    // Exchange the public token
    exchangeToken(publicToken);
  },
});
handler.open();

Step 3: Exchange the public token

Send a POST request to /auth/plaid/set_access_token with the public token from Plaid Link:
POST /auth/plaid/set_access_token HTTP/1.1
Authorization: <firebase-id-token>
Content-Type: application/x-www-form-urlencoded

public_token=public-sandbox-...
The server exchanges the public token for a long-lived access token, retrieves the account details, and stores the encrypted token in Firestore.
{
  "success": true
}

Viewing connected accounts

Retrieve the list of connected bank accounts:
GET /auth/plaid/accounts HTTP/1.1
Authorization: <firebase-id-token>
{
  "accounts": [
    {
      "bank_name": "Chase",
      "mask": [{"name": "Checking", "mask": "1234"}],
      "id": "uuid"
    }
  ]
}

Disconnecting a bank account

Remove a specific bank account by its id:
DELETE /auth/plaid/accounts/{account_id} HTTP/1.1
Authorization: <firebase-id-token>
{
  "success": true
}
If the deleted account is the last connected bank account, the user’s Plaid integration status is set to disconnected.
In development, ODAI connects to Plaid’s Sandbox environment. In production, it connects to Plaid’s Production environment. Use Plaid’s sandbox credentials and test institutions during local development.

Build docs developers (and LLMs) love