Home / Setup Guide
Setup Guide
How to set up your own TokenBroker from scratch, following the exact path this one took on 2026-11-28. Times are honest: about an hour of provisioning and deployment, most of it waiting on builds and sign-ins, plus ten minutes per provider bootstrap.
TokenBroker is an Azure Function that owns OAuth token renewal for services whose access tokens expire quickly. Callers hold only a static function key; the function holds each provider's refresh token and client secret in Azure Key Vault, mints fresh access tokens, and proxies API calls. If your tools keep dying with 401s an hour after every reconnect, this is the fix.
What you need first
- An Azure subscription, and an account allowed to create resource groups, Function Apps, and Key Vaults in it. If your tenant enforces MFA for resource changes (many do), have your authenticator ready: plain sign-in reads fine, but writes fail with AADSTS50076 until the sign-in carries an MFA claim. See the Azure Foundation page for the claims-challenge sign-in recipe.
- A git clone of this repo.
- Tooling on the machine you deploy from:
- .NET SDK 11.0.100 or later (the repo's
global.jsonpins 11.0.100, rollForward latestFeature) - Azure CLI (
az) - Azure Functions Core Tools v4 (
func)
- .NET SDK 11.0.100 or later (the repo's
- For each provider you want to broker: an account with that provider and permission to register an OAuth client in its developer console.
Step 1: Choose your names
Pick a resource group, a region, and globally unique names for the Function App, Key Vault, and storage account. Ours, as the worked example:
| Thing | Example |
|---|---|
| Resource group | rg-tokenbroker |
| Region | West US 2 (must be a Flex Consumption region) |
| Function App | tokenbroker-example |
| Key Vault | kv-tokenbroker-example |
| Storage account | sttokenbrokerexample |
The vault name and Function App name must be globally unique across Azure; add a short random suffix if yours are taken.
Step 2: Provision the Azure resources
Sign in with the MFA-capable flow if your tenant requires it, then:
az group create -n <rg> -l <region>
az storage account create -n <storage> -g <rg> -l <region> --sku Standard_LRS --allow-blob-public-access false
az keyvault create -n <vault> -g <rg> -l <region> --enable-rbac-authorization true
az functionapp create -n <app> -g <rg> --flexconsumption-location <region> --runtime dotnet-isolated --runtime-version 11.0 --functions-version 4 --storage-account <storage> --assign-identity [system]
Two choices here are forced, not taste:
- Flex Consumption. The classic Linux Consumption plan does not support .NET 10 or later.
- .NET 11 isolated worker. .NET 8 and 9 reached end of support on 2026-11-10, the day .NET 11 shipped, and the Functions in-process model retired the same day.
Step 3: Let the function read the vault
The Function App's system-assigned managed identity needs read access to the vault, and you need write access for bootstraps and rotations:
az role assignment create --assignee <app-identity-principal> --role "Key Vault Secrets User" --scope <vault-resource-id>
az role assignment create --assignee <your-user-object-id> --role "Key Vault Secrets Officer" --scope <vault-resource-id>
RBAC changes can take a few minutes to propagate. If a vault read fails right after this step, wait and retry before debugging anything else.
Step 4: The config file
Configuration lives in files under src/TokenBroker, never in code
and never in Azure app settings:
appsettings.json(committed) holds non-secret defaults: an emptyKeyVaultUriand each provider's base URLs underProviders:<Name>:....- Create
appsettings.Local.json(gitignored, it is in.gitignoreasappsettings.*.json) with your real vault URI:
{ "KeyVaultUri": "https://<vault>.vault.azure.net/" }
It is copied into the deployment package when present, so the
deployed function reads its config from the file. Environment
variables (how Azure app settings arrive) still override file values
if you ever need an override. Secrets are not configuration: they
live in the vault (Step 3), and the only local exception is
local.settings.json for vault-less local runs, also gitignored.
Step 5: Build and deploy
From src/TokenBroker, with az, the .NET SDK, and func on your
PATH:
dotnet build -c Release
func azure functionapp publish <app> --dotnet-isolated
A minimal local.settings.json (gitignored) containing
FUNCTIONS_WORKER_RUNTIME=dotnet-isolated must exist in that folder
for runtime detection; its values are not uploaded.
Step 6: Verify the empty broker
az functionapp function list -g <rg> -n <app>lists the deployed functions.- Call any route without a key: it must return 401. That proves function-key authorization is on.
- Get the caller key with
az functionapp keys list -g <rg> -n <app>(on Flex Consumption the default key is underfunctionKeys.default, nothostKeys.default). Callers send it as thex-functions-keyheader. Treat it like a password: it unlocks the proxy, though never the providers behind it.
Step 7: Add your first provider
The broker ships with Zoho wired up as the reference provider. To broker a provider of your own, follow Adding a Provider: register a dedicated OAuth client, put its id and secret in the vault, write two small classes, deploy, run the one-time grant-code bootstrap, and test one call end to end.
Running it locally
Copy src/TokenBroker/local.settings.json.example to
local.settings.json and either point KeyVaultUri at a vault your
sign-in can read, or leave it empty and supply each provider's three
values as plain settings (<Prefix>ClientId, <Prefix>ClientSecret,
<Prefix>RefreshToken). Never commit local.settings.json.
Ground rules that keep this safe
- Secrets live in the vault only. Client secrets are typed into the Azure portal by the account owner; they never pass through chat, email, or this repo.
- Grant codes are single-use and expire in minutes. The bootstrap is a short attended ceremony, not a batch job.
- One OAuth client per provider, dedicated to the broker. Never share a client with another tool, so rotating one never breaks the other.
- If a step fails, read the function's logs before retrying: a refused refresh is logged with the provider's exact response, which is the whole reason for owning the broker.