OAuth
OAuth overview
Authorize on behalf of users with the OAuth 2.0 Authorization Code flow.
Use OAuth when your application acts on behalf of a user — reading their data, posting on their behalf, or otherwise needing their explicit consent.
If you only need to authenticate your own server-to-server traffic, use a personal API token instead.
The flow at a glance
The Agentic Developer Hub uses the standard OAuth 2.0 Authorization Code flow with PKCE. Four steps:
- Register your app — get a
client_idand configure aredirect_uri. - Send the user to authorize — redirect the
user to
/api/oauth/signin/start. They sign in and approve scopes. - Exchange the code for tokens — your
server POSTs the returned code to
/api/oauth/signin/exchangeand receives an access token + refresh token. - Refresh when the token expires — exchange a
refresh token for a new access token at
/api/auth/refresh.
┌──────┐ ┌─────────┐ ┌──────────────┐
│ User │ │ Your │ │ Agentic │
│ │ │ App │ │ Developer │
│ │ │ │ │ Hub │
└──┬───┘ └────┬────┘ └──────┬───────┘
│ │ │
│ 1. Click "Connect" │ │
│ ───────────────────────►│ │
│ │ │
│ │ 2. Redirect to /auth/start │
│ ◄───────────────────────┤ │
│ │
│ 3. Sign in & approve scopes │
│ ────────────────────────────────────────────────────►│
│ │
│ 4. Redirect back to your redirect_uri with ?code=… │
│ ◄────────────────────────────────────────────────────│
│ │ │
│ │ 5. POST /auth/exchange │
│ │ {code, code_verifier} │
│ │ ──────────────────────────►│
│ │ │
│ │ 6. {access_token, │
│ │ refresh_token, │
│ │ expires_in} │
│ │ ◄──────────────────────────│
│ │ │What you'll need before you start
- A registered application with a
client_id. See Register an app. - A
redirect_uriyou control (an HTTPS URL on your domain, orhttp://localhost:<port>/callbackduring development). - A backend that can keep your
client_secretserver-side. The OAuth flow itself uses PKCE so the secret never travels through the user's browser, but anything you do post-token (refresh, revoke) must run server-side.
Common pitfalls
- The redirect_uri must match exactly. Including the trailing slash, the
port, the scheme. The mismatch is the #1 reason
/auth/exchangereturns400. - PKCE
code_verifieris required. This API rejects non-PKCE flows. See Step 2 for how to generate the verifier and challenge. - Access tokens expire. Always handle the
401 token_expiredresponse by refreshing — see Step 4.