1. Generate consent URL
┌─────────────────────────────────────────────┐
│ aivault oauth setup --provider google \ │
│ --auth-url https://accounts.google.com/... │
│ --client-id <id> --redirect-uri <uri> │
│ │
│ → Returns consentUrl — open in browser │
└─────────────────────────────────────────────┘
2. Exchange auth code for tokens (outside aivault)
┌─────────────────────────────────────────────┐
│ Use your own runtime or curl to exchange │
│ the auth code for access + refresh tokens. │
└─────────────────────────────────────────────┘
3. Store tokens in vault
┌─────────────────────────────────────────────┐
│ aivault secrets create --name SPOTIFY_OAUTH \ │
│ --value '{"clientId":"...","clientSecret": │
│ "...","refreshToken":"..."}' │
│ │
│ → Credential auto-provisioned: spotify │
└─────────────────────────────────────────────┘
4. Invoke (automatic token refresh)
┌─────────────────────────────────────────────┐
│ aivault invoke spotify/playlists ... │
│ │
│ Broker automatically: │
│ → Checks if access_token is expired │
│ → Refreshes via token endpoint if needed │
│ → Writes new tokens back to vault │
│ → Injects Bearer token into request │
└─────────────────────────────────────────────┘