client_id and client_secret in OAuth terms.
1
Generate PKCE values
Generate these fresh for every request. Only Keep the
S256 is accepted; plain is rejected.verifier in the session (or alongside state) and send it in step 3. If it falls outside the spec — 43 to 128 characters, allowed character set — the token exchange fails with invalid_grant.2
Send the user to the consent screen
Redirect the user’s browser to this address.Line breaks are for readability — send it as a single line with no whitespace.After the user signs in and grants consent, they return to your registered redirect URI.
3
Exchange the code for a token
Call this from your server. Calling it from a browser exposes your secret key.The
redirect_uri must be character-for-character identical to the one in step 2. The code is valid for 5 minutes and can be used once.4
Call the API with the token
/api/v1/** calls work the same way.Refreshing tokens
Access tokens expire after 15 minutes.Disconnecting
When a user asks to disconnect, revoke the token.Common errors
For safety, a failed redirect URI check shows the user a 400 page and never redirects to an unregistered address.
Before you go to production
- Never put your secret key in a browser or mobile app bundle. Exchange tokens on the server.
- Generate
stateper request and verify it in the callback. - Store refresh tokens per user, and overwrite with the new value on every refresh.
- When a user disconnects, revoke and delete the stored tokens.