Skip to main content

Overview

The Dropbox resource uses OAuth2 with a long-lived refresh token to authenticate against the Dropbox v2 HTTP API:
  • /2/files/list_folder, list folder entries
  • /2/files/download, download file bytes
  • /2/files/search_v2, search files by name/content
  • /2/files/get_metadata, fetch entry metadata
Two flows are supported:
  • Code flow with client secret, for Node/server. Needs client_id, client_secret, refresh_token.
  • PKCE flow, for browsers. Needs only client_id and refresh_token (no secret in the bundle).
Both produce the same long-lived refresh token; the resource auto-refreshes short-lived access tokens (≈4h) behind the scenes.

Setup

1. Create a Dropbox App

  1. Go to https://www.dropbox.com/developers/apps
  2. Click Create app
  3. Choose:
    • API: Scoped access
    • Access type: App folder (sandboxed to one folder Dropbox creates for you) or Full Dropbox (your entire account). Pick App folder for least privilege.
    • Name it (e.g., “Mirage”) -> Create app

2. Configure Permissions

On the app’s settings page, click the Permissions tab and check:
  • files.metadata.read, list folders, read file metadata
  • files.content.read, download file bytes
If you also want write/delete (not used by the read-only resource yet), check files.content.write and files.metadata.write. Click Submit at the bottom of the Permissions tab. Required: Dropbox does not include unchecked scopes in tokens, even if the auth URL requests them.

3. Configure OAuth 2 Redirect URI

On the Settings tab, scroll to OAuth 2 -> Redirect URIs and add:
  • For the CLI flow below: http://localhost:1
  • For the browser PKCE example: http://localhost:5173/dropbox_pkce.html
Click Add after each.

4. Copy the App Key (and Secret)

Still on Settings, copy:
  • App key, this is your DROPBOX_APP_KEY
  • App secret, click Show -> copy. This is your DROPBOX_APP_SECRET. Skip if you only need the PKCE flow.

5. Get the Refresh Token (CLI flow with client secret)

This mirrors the Google flow, easiest path for Node/server use. A) Open this URL in a browser (replace YOUR_APP_KEY):
  • token_access_type=offline, required to receive a refresh token. Without this you only get a short-lived access token.
B) Authorize: sign in -> click Allow. C) Copy the code: the browser redirects to http://localhost:1?code=ABC... (the page won’t load, expected). Copy the code value from the URL bar. D) Exchange the code for a refresh token:
The response contains refresh_token, save it. Example:

6. Set Environment Variables

Alternative: PKCE Flow (browser, no client secret)

If you’re mounting Dropbox from a browser SPA and don’t want to ship a client secret, use the PKCE flow. The bundled example does the dance end-to-end.
  1. In the Dropbox app Settings tab, ensure the redirect URI http://localhost:5173/dropbox_pkce.html is registered (Step 3).
  2. Set only DROPBOX_APP_KEY in .env.development at the repo root (no secret needed).
  3. From examples/typescript/browser/, run pnpm dev.
  4. Open http://localhost:5173/dropbox_pkce.html and click Connect Dropbox.
The example persists the refresh token to localStorage, then mounts a DropboxResource with just { clientId, refreshToken } and runs ls /dropbox/. Inspect DevTools -> Network -> filter token to confirm refresh calls don’t include client_secret. The same refresh_token can be reused for headless setups, copy it out of localStorage and set it as DROPBOX_REFRESH_TOKEN in your env.

Token Lifetime

Refresh tokens get revoked if: The DropboxTokenManager in the resource transparently exchanges the refresh token for a fresh access token whenever the cached one is within 5 minutes of expiry.

Scopes Reference

The Mirage resource only needs files.metadata.read + files.content.read for the read-only mount. Add the *.write scopes if/when write commands land.

Troubleshooting

For TypeScript usage, mount with:
Or browser (PKCE):