Skip to main content
CA Colombia API authenticates requests using cookie-based sessions. After a player completes OAuth with Discord or Roblox, the API issues two cookies — an access token and a refresh token — which are sent automatically with every subsequent request. You never handle raw tokens directly: the cookies carry the session, and the API silently renews them before they expire.

How Authentication Works

When a player completes the OAuth flow, the API sets two HTTP cookies on their browser or client: Every protected endpoint reads the access_token cookie on each request. If the token is within 5 minutes of expiry — or has been marked inactive — the middleware automatically exchanges it for a fresh pair using the refresh_token cookie. The renewed cookies are written to the response transparently, so the player’s session continues without any action required on your part.
Both cookies are scoped to the cacolombia.co domain. If you are running a companion application on a subdomain, ensure your client is configured to send cross-subdomain cookies or proxy requests through the same origin.

Starting the OAuth Flow

Initiate authentication by calling POST /v1/oauth/:provider. This endpoint returns a provider authorization URL that you redirect your user to. Supported providers
You must complete Discord OAuth before you can link a Roblox account. The Roblox provider requires an existing user session with a linked Discord account. Attempting the Roblox flow without one will fail and redirect the user to the platform home page.
Endpoint
Request body
The redirectUrl must be a whitelisted URL. Contact the CA Colombia team to add your domain to the allowlist. Response
Redirect your user to targetUrl. Store the state value so you can verify it matches when the callback arrives. Example

Handling the OAuth Callback

After the player authorizes with the provider, the API handles the callback at:
The API validates the state and code, retrieves the player’s profile from the provider, creates or retrieves their platform account, and then:
  1. Sets the access_token and refresh_token cookies on the response.
  2. Redirects the player to your original redirectUrl with ?state=<state> appended.
You do not call this endpoint directly — the provider redirects the player’s browser to it automatically. Once the player lands back on your redirectUrl, their session cookies are already set and ready to use. Callback redirect example
Use the returned state value to match against what you stored in Step 1 to confirm the flow completed for the right session.

Using Your Session

Once cookies are set, all subsequent API requests are authenticated automatically — no Authorization header is required. Simply include cookies in your requests.

Token Refresh

Token renewal is fully automatic and transparent. You do not need to implement any refresh logic. When the auth middleware processes a request and detects the access token is expiring within 5 minutes (or has already been marked inactive), it:
  1. Reads the refresh_token cookie from the request.
  2. Issues a new access token and refresh token pair.
  3. Writes the updated cookies to the response.
The new cookies are written on the same response that returns your API data, so the player’s next request is already using the fresh token without any round-trip delay. If the refresh token itself is missing or invalid, the server returns 401 FAILED_TOKEN_RENEWAL and the player must re-authenticate by starting the OAuth flow again.

Error Codes

When authentication fails, the API returns a 401 or 403 response with a JSON body containing a code field. Use this code to determine what went wrong and how to recover. Error response shape
Build a central response interceptor in your HTTP client that watches for 401 responses and automatically redirects the player to re-authenticate. This prevents stale sessions from surfacing as unexpected errors in your UI.