TokenBroker

Home / Token Setup

Token Setup

How TokenBroker holds tokens, and the pattern every provider follows. Provider-specific steps live on their own subpages; Zoho is the first (see the link at the bottom).

The pattern

  1. A dedicated OAuth client per provider, owned by TokenBroker. Never reuse a client that belongs to another tool. TokenBroker gets its own client id and secret so revoking or rotating one tool never breaks the other.
  2. Secrets live only in Azure Key Vault (kv-tokenbroker-example). The client secret is typed straight into the vault by the account owner. It is never pasted into chat, never stored on the assistant's machine, and never committed to this repo.
  3. The refresh token is minted once, by hand. OAuth grant codes are single-use and live only a few minutes, so the bootstrap is a short, attended ceremony: the owner generates a code, the assistant exchanges it immediately, and the refresh token goes directly into the vault. See the Zoho page for the worked example.
  4. The function mints access tokens at call time. The provider's token service (the shared OAuthTokenService base) reads the client id, client secret, and refresh token from the vault through the Function App's managed identity (DefaultAzureCredential), exchanges the refresh token at the provider, caches the access token in memory, and refreshes five minutes before expiry. Providers rate-limit refresh: Zoho allows at most 10 access tokens per refresh token per 10 minutes, which is why the cache matters.
  5. Callers authenticate with the Azure function key (header x-functions-key). The key is the only credential a caller holds; it unlocks the proxy, not the provider.

Security rules

Adding a new provider (checklist)

  1. Register a dedicated OAuth client for TokenBroker with the provider; note the exact scopes the proxy needs, no more.
  2. Put <provider>-client-id and <provider>-client-secret in the vault (owner types them in the Azure portal).
  3. Add a token service and proxy functions under src/TokenBroker, following the Zoho shape; add the provider's base URLs as app settings (<Provider>AccountsBase, <Provider>MailBase style).
  4. Build clean, deploy (see Azure Foundation), and confirm the new functions are listed.
  5. Run the grant-code bootstrap; store <provider>-refresh-token in the vault.
  6. Test one read call end to end with the function key; record the date and result on the provider's wiki page.
  7. Add the provider page under this section: scopes, secret names, endpoints, limits, and its troubleshooting notes.

Doing it yourself

Providers