By the end of this guide, an application backend calls third-party APIs on behalf of any logged-in user, without storing tokens and without trackingDocumentation Index
Fetch the complete documentation index at: https://docs.alterauth.com/llms.txt
Use this file to discover all available pages before exploring further.
grant_id in the application database.
The flow:
- The end user clicks Connect Google in the frontend.
- Alter Connect runs the OAuth flow and writes a grant bound to that user’s identity.
- The backend calls
app.request()with the user’s JWT in scope. The SDK resolves the grant from the JWT, refreshes the token, injects it, and returns the response.
Prerequisites
- An app with a
alter_key_app_…API key. - An identity provider configured for the app (Auth0, Clerk, Okta, or custom OIDC). End users must already be authenticated through the IDP when they reach the backend.
- A provider configured — this guide uses Google as the example.
- The Alter SDK installed and the Connect SDK installed in the frontend.
Walkthrough
1. Mint a Connect session on the backend
When the user clicks Connect Google in the frontend, the frontend asks the backend for a short-lived session token. The backend mints it via the SDK:2. Open the Connect widget on the frontend
onSuccess with the connection metadata. The grant is now stored in Alter, bound to this user.
3. Call the provider from the backend
The backend constructs the SDK once with auser_token_getter that returns the calling user’s JWT. Every request() carries the JWT; the SDK resolves the grant per-call.
grant_id, only provider. The backend uses the JWT to find the grant.
Patterns
Multi-account users
A user can have more than one Google account connected. Whenapp.request(provider="google") matches multiple grants, the SDK raises AmbiguousGrantError with the account identifiers. Prompt the user to pick:
Listing the user’s connections
For an in-app “Connected accounts” page, list grants visible to the calling user:Revoking a grant from the backend
Troubleshooting
| Error | Likely cause | Fix |
|---|---|---|
GrantNotFoundError | The JWT did not match any grant. | The user hasn’t completed Connect yet. Show the Connect widget. |
AmbiguousGrantError | The user has connected the provider more than once. | Pass account=... per the multi-account pattern above. |
GrantRevokedError / CredentialRevokedError | User revoked in the Wallet or at the provider. | Show the Connect widget to re-authorize. |
ScopeReauthRequiredError | The app added a required scope after the user connected. | Show the Connect widget to re-authorize with the new scope set. |
PolicyViolationError | A policy denied the call (time-of-day, IP, rate). | Inspect e.policy_error. See Policies. |
What’s next
Embed the Connect widget
Frontend integration details.
Give an agent scoped access
Let an AI agent call providers on the user’s behalf.
Identity resolution
The three modes in depth.