Obtain an API Access Token
This guide explains how to obtain an ACP platform access token via API calls. It is intended for scenarios where you need to access platform APIs programmatically.
TOC
OverviewPrerequisitesStepsStep 1: Retrieve Login MetadataStep 2: Obtain the Dex Request IDStep 3: Retrieve the RSA Public KeyStep 4: Submit Encrypted Credentials and Obtain the Authorization CodeStep 5: Exchange the Authorization Code for a TokenComplete ExampleShell Script (curl)Using the TokenImportant NotesOverview
ACP uses a Dex-based OIDC authentication system. The login flow follows the OAuth 2.0 Authorization Code Flow and consists of five API calls that must be completed within the same HTTP session (sharing cookies).
The entire flow must use the same HTTP session (shared cookie jar). Step 2 sets the cpaas_oidc_auth_flow session cookie, which Step 5 requires to issue a token. Without this cookie, Step 5 returns invalid authentication session.
Prerequisites
Steps
Step 1: Retrieve Login Metadata
Request:
Query parameters:
Response (200 OK):
The code_challenge and related parameters in auth_url are generated server-side for the server-to-Dex PKCE exchange and stored in the cpaas_oidc_auth_flow cookie. You do not need to interpret them. In Step 2, pass the complete query string from auth_url as-is.
Step 2: Obtain the Dex Request ID
Use the query parameters from the auth_url returned in Step 1.
This step sets the cpaas_oidc_auth_flow session cookie. All subsequent requests must carry this cookie.
Request:
Where {query_from_auth_url} is the complete query string extracted from the Step 1 auth_url (forward it unchanged):
Response (200 OK):
Step 3: Retrieve the RSA Public Key
Request:
Response (200 OK):
Step 4: Submit Encrypted Credentials and Obtain the Authorization Code
Password encryption:
- Construct a JSON payload:
{"ts": "<ts from Step 3>", "password": "<plaintext password>"} - Encrypt the JSON bytes using the RSA public key with PKCS#1 v1.5 padding
- Base64-encode the encrypted result (standard encoding, not URL-safe)
Request:
Path parameter:
Query parameter:
Request body:
Response (200 OK):
Extract the code and state parameters from redirect_url for use in Step 5.
Step 5: Exchange the Authorization Code for a Token
Request:
Query parameters:
Response (200 OK):
Complete Example
Shell Script (curl)
curl maintains the session by sharing a cookie jar file via -c (write cookies) and -b (read cookies).
Dependencies: curl, jq (JSON parsing), openssl (RSA encryption)
Usage:
Using the Token
Include the access_token in the Authorization header of all subsequent API requests:
Important Notes
-
Session cookie must be shared: The entire login flow must use the same HTTP session (shared cookie jar) so that the
cpaas_oidc_auth_flowcookie is automatically carried through each step. Without this cookie, Step 5 returnsinvalid authentication session (400). -
The
tstimestamp cannot be reused: Thetsreturned in Step 3 is unique per request. It must be combined with the password into a JSON payload before encryption. Reusing a previoustsvalue will cause Step 4 authentication to fail. -
Choosing the
IDPparameter:local: ACP local accounts (default)ldap: LDAP/AD domain accounts; the exact ID depends on your platform configuration
-
TLS certificate verification: The
-kflag in the example script skips certificate verification. This is only suitable for test environments with self-signed certificates. In production, remove-kand either configure a valid CA certificate or add the platform CA to your system trust store.