English Version
Authentication & Login
All API Broker APIs use Bearer (JWT) token-based authentication managed through AWS Cognito. Every API request must include a valid token in the authorization header. Without it, the API returns 401 Unauthorized.
Authentication Process
Step 1 — Login
The first step is to obtain a token by calling the login endpoint with the credentials assigned by API Broker.
Endpoint
POST /api/auth/loginRequest body:
{
"username": "your_username",
"password": "your_password"
}Response:
{
"AccessToken": "eyJraWQiOiJ...",
"ExpiresIn": 3600,
"TokenType": "Bearer",
"RefreshToken": "eyJjdHkiOiJ...",
"IdToken": "eyJraWQiOiJ..."
}| Field | Description |
|---|---|
AccessToken | Primary token. Used in all requests as a Bearer token |
ExpiresIn | Token lifetime in seconds. Default: 3600 (1 hour) |
TokenType | Always "Bearer" |
RefreshToken | Token used to renew the session without logging in again with username and password |
IdToken | Cognito identity token. Internal use |
Save both the
AccessTokenand theRefreshToken. The first is used in every request; the second allows you to renew the session when theAccessTokenexpires without prompting for a password again.
Step 2 — Use the token in every request
All API endpoints require the AccessToken in the Authorization header:
Authorization: Bearer {AccessToken}
Example:
curl -X GET https://apibroker.prd-adcap.com/api/accounts/persons?person_id=F-9686d35b \
-H "Authorization: Bearer eyJraWQiOiJ..."In code:
const response = await fetch('https://apibroker.prd-adcap.com/api/accounts/persons', {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});Step 3 — Refresh the token
The AccessToken expires after 3600 seconds (1 hour). When that happens, the API returns 401 Unauthorized. To avoid interrupting operations, there are two options:
Option A — Log in again (simpler)
Call POST /api/login again with your username and password to obtain a fresh AccessToken.
Option B — Use the Refresh Token (recommended for production integrations)
The RefreshToken has a longer lifespan and allows you to obtain a new AccessToken without exposing credentials on every request. This is ideal for continuously running systems.
Credentials
Access credentials (username and password) are assigned by the API Broker team during the integration process, at the Staging Credentials stage and later at the Production Credentials stage.
If you need credentials or access resets, contact your account manager or write to [email protected].
Security best practices:
- Never include credentials directly in source code.
- Store them as environment variables or in a secrets manager.
- Do not share them across teams without authorization.
- Rotate them periodically or at any sign of compromise.
Authentication-related response codes
| Code | Meaning | Recommended action |
|---|---|---|
200 OK | Successful login. Valid token | Continue |
401 Unauthorized | Token expired or missing | Log in again or use the Refresh Token |
403 Forbidden | Valid token but insufficient permissions | Verify user permissions or contact support |
500 Internal Server Error | Server error | Retry. If it persists, contact support |
Recommended Implementation
For production integrations, the recommended approach is:
- On application startup, perform the login and store the
AccessTokenandRefreshTokenin memory (never in public storage). - On every request, attach the
AccessTokenin theAuthorizationheader. - On receiving a
401, attempt to automatically refresh the token using theRefreshTokenbefore propagating the error to the user. - If the refresh also fails, initiate a new login with credentials.
This ensures a seamless experience with no interruptions due to session expiration.
Key Points to Remember
- Every request needs
Authorization: Bearer {AccessToken}— no exceptions. - The token expires in 1 hour. Implement automatic renewal in production.
- Credentials are environment-specific. STG and PRD have separate users.
401= expired or missing token.403= insufficient permissions. These are different errors.- Never hardcode credentials in source code or repositories.
- Credentials are assigned by API Broker during the integration process. They are not self-managed.
Updated 6 months ago
