OAuth flow
HalationLab.ai uses OAuth 2.0 authorisation code with PKCE (S256). The authorisation server is https://app.halationlab.ai; the API is the resource https://api.halationlab.ai/v1.
| URL | |
|---|---|
| Discovery (RFC 8414) | https://app.halationlab.ai/.well-known/oauth-authorization-server |
| Authorisation endpoint | https://app.halationlab.ai/oauth/authorize |
| Token endpoint | https://app.halationlab.ai/oauth/token |
| Revocation endpoint | https://app.halationlab.ai/oauth/revoke |
| Resource | https://api.halationlab.ai/v1 |
Read the discovery document rather than hard-coding endpoints where your OAuth library supports it.
1. Send the user to the authorisation endpoint
Section titled “1. Send the user to the authorisation endpoint”Create a random code verifier and its S256 challenge, and a random state. Send the user to the authorisation endpoint with response_type=code, your client_id and redirect_uri, the scope you need, state, code_challenge, code_challenge_method=S256 and resource=https://api.halationlab.ai/v1.
// Builds the authorisation URL for the OAuth authorisation code flow with PKCE (S256), and the verifier to keep// for the token exchange. Run: HL_OAUTH_CLIENT_ID=... HL_OAUTH_REDIRECT_URI=... node authorize-url.tsimport { createHash, randomBytes } from 'node:crypto';
const clientId = process.env.HL_OAUTH_CLIENT_ID ?? 'your-client-id';const redirectUri = process.env.HL_OAUTH_REDIRECT_URI ?? 'http://127.0.0.1:8765/callback';
const codeVerifier = randomBytes(32).toString('base64url');const codeChallenge = createHash('sha256').update(codeVerifier).digest('base64url');const state = randomBytes(16).toString('base64url');
const url = new URL('https://app.halationlab.ai/oauth/authorize');url.search = new URLSearchParams({ response_type: 'code', client_id: clientId, redirect_uri: redirectUri, scope: 'read generate offline_access', state, code_challenge: codeChallenge, code_challenge_method: 'S256', resource: 'https://api.halationlab.ai/v1',}).toString();
// Send the user to `url`. Keep `state` and `codeVerifier` (server-side or in session storage) until the callback.console.log(url.href);console.log({ state, codeVerifier });2. The user consents
Section titled “2. The user consents”The user signs in and sees your app’s name and the permissions it asks for. On the consent screen they choose the projects to share, set the app’s spending limit, and accept the upload rights and processing terms if your app uploads files. They can grant less than you asked for.
3. Exchange the code
Section titled “3. Exchange the code”The user returns to your redirect_uri with code and state. Check state, then exchange the code at the token endpoint with the code_verifier and the same resource:
# Exchanges the authorisation code from the callback for an access token, then refreshes it.# A server app also authenticates with its client secret (here in the Authorization header: client_secret_basic).set -euo pipefail
curl -sS --fail-with-body https://app.halationlab.ai/oauth/token \ -u "$CLIENT_ID:$CLIENT_SECRET" \ -d grant_type=authorization_code \ -d code="$CODE" \ -d redirect_uri="$REDIRECT_URI" \ -d code_verifier="$CODE_VERIFIER" \ -d resource=https://api.halationlab.ai/v1
# Later, with the refresh token (needs the offline_access scope):curl -sS --fail-with-body https://app.halationlab.ai/oauth/token \ -u "$CLIENT_ID:$CLIENT_SECRET" \ -d grant_type=refresh_token \ -d refresh_token="$REFRESH_TOKEN" \ -d resource=https://api.halationlab.ai/v1That example is for a server app with client_secret_basic. A public client (desktop or browser app) sends client_id in the body instead of a secret.
The response holds the access token, and a refresh token when offline_access was granted. Send the access token as Authorization: Bearer … to the API.
4. Refresh and revoke
Section titled “4. Refresh and revoke”Refresh with grant_type=refresh_token (needs offline_access). Revoke a token at the revocation endpoint when the user disconnects.
An access token that is invalid, expired or whose connection has ended gets 401 access_token_invalid: refresh it, or ask the user to connect your app again. Users can disconnect your app at any time in Account → Connected apps.
What the app can see
Section titled “What the app can see”Call GET /v1/account with the access token: it returns the scopes granted, the projects shared (all or a list), the default project and the spending limit. A request outside them gets 403 insufficient_scope, or 404 not_found for an object in a project that was not shared.