Authentication Guide
Use authorization code or client credentials access, obtain tokens, and renew them for ELECQ Open Access.
ELECQ Open Access uses OAuth 2.0 for both user-authorized access and backend application access. All grants use the same Token endpoint: POST https://api.elecq.com/api/v1/oauth2/token.
Choose your integration flow
| Scenario | Grant type | User login and consent | Token renewal |
|---|---|---|---|
| Access resources on behalf of a user | authorization_code | Required initially | Use a refresh token when one is issued. |
| Renew a user-authorized access token | refresh_token | Not required while the refresh token is valid | Store a replacement refresh token when returned. |
| Access resources assigned to your backend application | client_credentials | Not required | Request a new access token with the client credentials. |
Use Authorization Code Flow when access depends on a user's authorization. Use Client Credentials when your backend acts as the application itself.
Authentication at a glance
| Request | Authentication |
|---|---|
POST /api/v1/oauth2/token for any of the three grants | HTTP Basic: client_id as the username and client_secret as the password. |
/api/v1/access/** resource endpoints | HTTP Bearer: the issued access_token, subject to the endpoint's scope and resource permissions. |
A refresh_token is submitted as a form field when renewing a user-authorized access token. Use the access_token to call resource APIs; an id_token is not a substitute. The client credentials flow does not issue a refresh token or an ID token.
Before you begin
- Obtain a
client_idandclient_secretfrom your ELECQ integration contact. Use separate client IDs for User Access (authorization_codeandrefresh_token) and Application Access (client_credentials); scopes and token lifetimes are configured independently. - Confirm the grant types, scopes, and resource access enabled for your client.
- For authorization code access, register your application's callback URL. The example below requests
openid device.read. - For client credentials access, enable
client_credentialsand theclient_secret_basicauthentication method. No callback URL or user login is needed. - Keep client secrets, access tokens, and refresh tokens on your backend. All example credentials and tokens on this page are placeholders.
Authorization Code Flow
A user grants access to their resources, and your application exchanges the authorization code for an access token.
1. Ask the user to authorize access
Open the authorization URL in the user's browser. Replace the client ID, callback URL, scopes, and state with your application's values:
https://api.elecq.com/api/v1/oauth2/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=https%3A%2F%2Fyour-app.example%2Foauth%2Fcallback&scope=openid%20device.read&state=YOUR_RANDOM_STATEGenerate a fresh random state for the authorization request. After consent, your callback receives code and state; verify that the returned state matches the value your application stored.
2. Exchange the authorization code
Send a form-encoded request to Obtain / Refresh Tokens. The redirect_uri must match the registered callback used in the authorization request.
In the API Reference, select Authorization Code Exchange in the Form Data dropdown.
curl --request POST 'https://api.elecq.com/api/v1/oauth2/token' \
--user 'YOUR_CLIENT_ID:YOUR_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'Use the returned access_token for resource requests. Store a refresh_token if one is issued, and use the response's expires_in value to plan when to refresh.
3. Call a resource endpoint
Use Hello Test to verify your access token.
curl --request GET 'https://api.elecq.com/api/v1/access/hello' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'For manual testing in the API Reference, enter the token value in the Bearer credential field. ReadMe adds the Authorization: Bearer header.
4. Refresh an access token
This section applies to user-authorized access. Use the same Token endpoint and the same HTTP Basic authentication. This flow requires grant_type=refresh_token and the latest refresh token; it does not require an authorization code or redirect URI.
In the API Reference, select Refresh Token in the Form Data dropdown to show the refresh fields.
curl --request POST 'https://api.elecq.com/api/v1/oauth2/token' \
--user 'YOUR_CLIENT_ID:YOUR_CLIENT_SECRET' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'refresh_token=YOUR_REFRESH_TOKEN'Use the new access token. If the response includes a replacement refresh token, store it for subsequent refreshes; otherwise, keep the existing refresh token. If the refresh token is no longer valid, restart the authorization code flow.
Client Credentials (Application Access)
Use client_credentials for a pure API integration where a backend application accesses resources assigned to the application itself, such as organization device import. This flow needs no browser login, consent page, authorization code, or redirect URI.
1. Confirm application permissions
Your ELECQ integration contact must enable client_credentials, client_secret_basic, the allowed scopes, and the application's resource access before you request a token. Use your dedicated Application Access client ID and only the scopes assigned during onboarding. Provide ELECQ with the client's recipient RSA public key in PEM format and the corresponding client ID. Wait for confirmation of activation before requesting organization device pages; see Business Data Encryption.
The following scopes apply to List Organization Devices and must be enabled for your client before you request them:
| Scope | Permission |
|---|---|
application.device.read | Read device identifiers and product models within the current organization's assigned device data range. |
application.device.credentials.read | Read device PINs and Random Codes within the current organization's assigned device data range. |
Request only the permissions your integration needs. openid and profile describe user identity and are not used for this application-only flow.
2. Request an application access token
Send a form-encoded request to the same Obtain / Refresh Tokens API, authenticated with HTTP Basic.
| Form field | Required | Value |
|---|---|---|
grant_type | Yes | client_credentials |
scope | No | A space-separated list of scopes assigned to your client. Send it explicitly to request the permissions needed. Omitting it grants no resource API scopes. |
Do not send code, redirect_uri, or refresh_token for this grant. Replace the placeholders and use scopes enabled for your client:
curl --request POST 'https://api.elecq.com/api/v1/oauth2/token' \
--user 'YOUR_CLIENT_ID:YOUR_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'Example response:
{
"access_token": "YOUR_APPLICATION_ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "application.device.read application.device.credentials.read"
}The token and lifetime above are illustrative. Use the actual expires_in value, in seconds, returned by the server. This flow returns no refresh_token or OIDC id_token.
3. Call a permitted resource API
Send the returned token in the Authorization: Bearer header. Start with Hello Test to check authentication:
curl --request GET 'https://api.elecq.com/api/v1/access/hello' \
--header 'Authorization: Bearer YOUR_APPLICATION_ACCESS_TOKEN'A successful Hello response confirms authentication. It does not verify device-list permissions or recipient-key configuration. Each business API separately checks the required scopes and the application's assigned data range.
For organization device import, call List Organization Devices with the application token and Accept: application/jose. Its successful pages are always encrypted. Decrypt and verify each page, upsert by deviceId, then continue with nextCursor and unchanged query parameters until hasMore is false. Start without time filters for a complete reconciliation.
An application token does not represent an end user. User-device APIs such as List Devices require user authorization; they cannot be used as organization-device APIs simply by changing grant_type. Use endpoints explicitly documented for application access. Requesting or receiving a scope does not create a new resource endpoint.
4. Renew the application access token
Cache the access token on your backend and reuse it until shortly before expiry. Request a new token by repeating the client_credentials request with the same client authentication and required scopes. Use the new access token for subsequent resource requests. A new token for the same client and organization can continue an unexpired device-list cursor; token renewal does not require restarting pagination.
Do not use grant_type=refresh_token for this flow, restart browser authorization, or request a new token for every API call. If an API returns 403, check its scopes and resource permissions instead of repeatedly requesting tokens.
Encrypted business responses
List Organization Devices requires JWE for every successful page, including basic fields. For business APIs that explicitly declare application/jose, follow Business Data Encryption to register recipient keys and decrypt JWE responses. HTTPS and Bearer authentication remain required. The OAuth2 Token response remains ordinary JSON; choosing client_credentials alone does not activate response encryption.
Troubleshooting
| Response | What to check |
|---|---|
400 invalid_grant | The authorization code or refresh token is invalid, expired, or already used where applicable. Restart user authorization if refreshing fails with this error. |
400 unauthorized_client | Confirm that the requested grant type, including client_credentials, is enabled for your client. |
400 invalid_scope | Request only scopes assigned to your client and separate multiple scopes with spaces. |
401 invalid_client | Verify the client ID, client secret, secret expiry, and HTTP Basic authentication on the Token request. |
401 from a resource endpoint | Check that the Bearer access token is present and valid. Renew an expired user token with its refresh token when available; renew an application token with client_credentials. |
403 from a resource endpoint | Check the required scopes, token type, audience, and the user's or application's resource permissions. A new token alone does not grant missing permissions. |
API reference
- Obtain / Refresh Tokens — authorization code exchange, refresh, and application token requests use the same endpoint.
- Hello Test — verify Bearer token authentication.
- List Devices — list devices for an authorized user.
- List Organization Devices — import and reconcile devices assigned to the current organization.
- Business Data Encryption — PEM public key submission, JWE processing, and key rotation.
Updated 18 days ago
