Obtain user or application access tokens using authorization_code, refresh_token, or client_credentials.
| Time | Status | User Agent | |
|---|---|---|---|
Retrieving recent requests… | |||
Obtain tokens through authorization_code, refresh_token, or client_credentials.
All three flows use POST https://api.elecq.com/api/v1/oauth2/token with
Content-Type: application/x-www-form-urlencoded.
Authenticate using HTTP Basic authentication: use your client_id as the
username and your client_secret as the password. This produces the header
Authorization: Basic <base64(client_id:client_secret)>.
Authorization Code Exchange
Use this flow to access User Access APIs on behalf of an authorized user.
Scopes and the authorization request
Request permissions in the scope query parameter of
GET https://api.elecq.com/api/v1/oauth2/authorize, before exchanging the code.
Use a space-separated, case-sensitive list and URL-encode it in the authorization
URL. Every requested scope must first be enabled for your client by ELECQ.
| Scope | Purpose | Related APIs |
|---|---|---|
openid | Requests OpenID Connect authentication and an ID token. It does not grant device permissions. | Optional when your integration also needs an ID token. |
device.read | Read the authorized user's device list and device details. | List Devices, Device Details |
device.execute | Permission checked by the charging-control operations. | Start Charge, Stop Charge |
device.write | Register or remove third-party OCPP server configuration and device credentials. | Register Device Credentials, Offboard Device Credentials |
These scopes are independent: device.write does not include device.read or
device.execute. Request only the permissions your integration needs. An
openid-only token does not satisfy the device API scope checks. The organization
scopes application.device.read and application.device.credentials.read belong to
Application Access and its
client_credentials flow.
Example authorization URL for an OIDC integration that reads devices (replace the
client ID, registered callback, and random state):
https://api.elecq.com/api/v1/oauth2/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fyour-app.example%2Foauth%2Fcallback&scope=openid%20device.read&state=RANDOM_STATECheck the returned state against the value saved for this authorization request.
After login and authorization, the callback receives a single-use code.
Exchange the authorization code
Authenticate with HTTP Basic using the same client ID and secret, then submit:
grant_type:authorization_code.code: the authorization code received by your callback.redirect_uri: the same registered redirect URI used in the authorization request.
The access token inherits the scopes approved during authorization. Do not add a
scope form field here to request or expand permissions; start a new authorization
request when additional permissions are needed.
curl --request POST 'https://api.elecq.com/api/v1/oauth2/token' \
--user 'CLIENT_ID:CLIENT_SECRET' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code=AUTH_CODE_FROM_CALLBACK' \
--data-urlencode 'redirect_uri=https://your-app.example/oauth/callback'Successful response
The response is 200 OK with Content-Type: application/json. Token fields are
at the top level, without a business-response wrapper or JWE encryption.
Example for the openid device.read authorization above, with refresh-token
issuance enabled for the client. All tokens are placeholders and 3600 is an
illustrative lifetime, not a fixed service value:
{
"access_token": "ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "openid device.read",
"refresh_token": "REFRESH_TOKEN",
"id_token": "ID_TOKEN"
}| Field | Type | Meaning and return condition |
|---|---|---|
access_token | string | Token for resource API calls. Send it as Authorization: Bearer ACCESS_TOKEN. |
token_type | string | Bearer. |
expires_in | integer | Access-token lifetime in seconds. Use the returned value; the lifetime is configured per client. It is not the refresh-token lifetime. |
scope | string | Granted access-token scopes, separated by spaces. Returned when the granted scope set is non-empty. Treat them as an unordered set and check that the permissions needed by your integration are present. |
refresh_token | string, conditional | Issued for this confidential-client flow when the client is enabled for the refresh_token grant. Its issuance does not depend on requesting openid. Store it on your backend and use the Refresh Token flow. |
id_token | string, conditional | Returned for OpenID Connect authorization using openid. It represents user authentication and must not replace the access token in resource API calls. |
Without openid, the response has no id_token. For example, authorization with
scope=device.read and refresh-token issuance enabled returns:
{
"access_token": "ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "device.read",
"refresh_token": "REFRESH_TOKEN"
}If refresh-token issuance is not enabled for the client, refresh_token is omitted.
Do not infer a fixed access-token or refresh-token lifetime from these examples.
An authorization error invalid_scope means that a requested scope is not allowed
for the client. A Token error invalid_grant can indicate an expired, already-used,
or mismatched authorization code; restart the authorization flow. A resource API
can return 403 when its required scope is missing, even if the token is otherwise
valid. Scope permission also does not grant access to another user's devices.
Protocol reference: OAuth 2.0 successful Token response.
Refresh Token
To obtain a new access token without asking the user to authorize again,
submit the following form fields to this same endpoint:
grant_type:refresh_token.refresh_token: the latest refresh token issued to your client.
The authorization code and redirect URI are not required for this flow.
On success, use the new access_token. If the response includes a new
refresh_token, replace the stored refresh token with it; otherwise,
continue using the existing refresh token.
If refreshing fails with 400 invalid_grant, restart the authorization
code flow. For 401 invalid_client, verify your client credentials.
Client Credentials (Application Access)
A backend application obtains an access token directly using its registered
client credentials. No browser login, user consent, authorization code,
redirect URI, or existing refresh token is needed.
Use a dedicated Application Access client ID and secret, separate from the User Access client configured for authorization_code and refresh_token. Scopes and token lifetime are configured independently for each client.
grant_type:client_credentials(required).scope: optional space-separated scopes assigned to the client. Send
the scopes explicitly to request only the permissions needed. If scope is omitted, no resource API scopes are granted.
The client must be enabled for this grant type and its authentication
method must match the request. Use HTTP Basic as described above. The
application scopes shown in the request example must first be assigned to
your client during onboarding.
For List Organization Devices, request application.device.read. Add application.device.credentials.read when requesting PIN or Random Code fields. These scopes do not grant access to User Access APIs. Before calling the device-list endpoint, provide ELECQ with your PEM public key file and client ID, and wait for confirmation of activation as described in Business Data Encryption. The Token request itself does not require JWE encryption.
curl --request POST 'https://api.elecq.com/api/v1/oauth2/token' \
--user 'APPLICATION_CLIENT_ID:CLIENT_SECRET' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=application.device.read application.device.credentials.read'A successful response contains an access_token, token_type, expires_in,
and the granted scope when applicable. It contains no refresh_token or
id_token for this flow. Example (illustrative lifetime and placeholder token):
{
"access_token": "ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "application.device.read application.device.credentials.read"
}Cache the access token and send it as a Bearer token to the permitted
resource APIs. At expiry, repeat the client_credentials request instead
of using the refresh_token grant. An application token does not represent
an end user. Resource APIs separately enforce their required scopes and
the application's assigned data range.
If the grant type is not enabled, expect 400 unauthorized_client; if a
requested scope is not allowed, expect 400 invalid_scope. Invalid client
credentials result in 401 invalid_client. The Token response is ordinary
JSON, even when a business endpoint uses the JWE Compact encryption profile.
400Invalid token request, invalid or expired authorization grant, disallowed grant type (unauthorized_client), or unapproved scope (invalid_scope).
401Client authentication failed (invalid_client). Verify the client ID, secret, secret expiry, and configured client authentication method.
