OAuth Setup
OAuth Setup
API v1 uses the OAuth 2.0 Authorization Code flow for authentication. This page documents the confidential-client variant: your server holds a client_secret and presents it at the token endpoint, so PKCE is not required (the secret serves the same binding purpose). PKCE is supported if you want defense-in-depth — include code_challenge/code_challenge_method in the authorization URL and code_verifier in the token exchange.
This page walks through the full flow: registering a client, directing the user to Credal to authorize, exchanging the resulting code for an access token, and calling the API.
1. Register an OAuth client
Creating an OAuth client requires approval from your organization’s admin. To request one, ask your admin to contact support@credal.ai.
After registration you’ll receive a client ID and client secret. Keep the client secret secure — treat it like a password.
2. Direct the user to Credal to authorize
Send the user to the Credal authorization endpoint. They’ll be asked to sign in (if not already) and approve the requested scopes.
After the user approves, Credal redirects to your redirect_uri with a short-lived authorization code:
3. Exchange the code for an access token
The authorization code is not an access token. You must exchange it by making a server-side POST request to the token endpoint. Do not skip this step.
The response contains the tokens you’ll use to call the API:
A few things to note:
- The authorization code expires in 10 minutes and is single-use. Exchange it immediately after receiving it.
- The
redirect_urimust match the one used in step 2 exactly.
4. Call the API
Pass the access_token to the Credal SDK:
5. Refresh the access token
Access tokens expire after 1 hour. Use the refresh_token to get a new one without sending the user through the browser flow again:
Refresh tokens are valid for 30 days and are rotated on every use — each refresh response includes a new refresh_token that replaces the old one. Always persist the new value; the previous token is immediately invalidated. If a refresh token expires, the user will need to go through the browser authorization flow again.