oauthTokenV2: Exchange or refresh OAuth tokens
oauthTokenV2: Exchange or refresh OAuth tokens
Function details
Obtain or refresh the end user's OAuth access token after H5 authorization. This endpoint uses form-urlencoded body and HTTP Basic authentication with the OAuth project Access Key and Secret Key — not the standard Open API JSON body with system / params / id.
See OAuth 2.0 authorization for the authorization code callback flow.
Request address
POST https://openapi-[DataCenter].easy4ip.com/openapi/oauthTokenV2
Replace [DataCenter] with your developer account data center (see Development specification).
Authentication
| Header | Value |
|---|---|
Authorization | Basic + Base64(ProjectAccessKey:ProjectSecretKey) |
Content-Type | application/x-www-form-urlencoded |
Reference: RFC 2617 §2 (HTTP Basic).
Grant type: authorization_code
Exchange the authorization code from the callback URL for tokens.
Form body
| Parameter | Required | Description |
|---|---|---|
| grant_type | Yes | authorization_code |
| code | Yes | Authorization code from the callback code query parameter |
| redirect_uri | No | Optional. Same callback URL as configured for the OAuth project. The Open Platform token endpoint does not validate this field; send it only if your client or authorization server requires it. |
Sample request
POST /openapi/oauthTokenV2 HTTP/1.1
Host: openapi-fk.easy4ip.com
Authorization: Basic <base64(ProjectAccessKey:ProjectSecretKey)>
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=XXXXXXXXXXXXXXXXXX&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
Grant type: refresh_token
Refresh the access token before expires_in elapses.
Form body
| Parameter | Required | Description |
|---|---|---|
| grant_type | Yes | refresh_token |
| refresh_token | Yes | refresh_token from a prior successful response |
Sample request
POST /openapi/oauthTokenV2 HTTP/1.1
Host: openapi-fk.easy4ip.com
Authorization: Basic <base64(ProjectAccessKey:ProjectSecretKey)>
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=QWU3723JDDUFH2382
Response (success)
HTTP 200, Content-Type: application/json;charset=UTF-8, Cache-Control: no-store, Pragma: no-cache.
| Field | Type | Description |
|---|---|---|
| access_token | String | End user access token (Ot_ prefix), bearer type |
| token_type | String | bearer |
| expires_in | Number | Lifetime in seconds (7200) |
| refresh_token | String | Use for the next refresh grant |
| scope | String | Current value all |
Sample response
{
"access_token": "Ot_xxxxxxxxxxxxxxxxxx",
"token_type": "bearer",
"expires_in": 7200,
"refresh_token": "QWU3723JDDUFH2382",
"scope": "all"
}
Error responses
This endpoint uses the OAuth 2.0 token error format, not the standard Open API result JSON layout. On failure the HTTP status is typically 200 or 400 and the body is JSON with an error field.
error | When |
|---|---|
invalid_request | Missing or empty grant_type, code, or refresh_token; malformed Authorization header |
invalid_client | Unknown OAuth project Access Key / Secret Key, or token exchange failed |
unsupported_grant_type | grant_type is not authorization_code or refresh_token |
Related
Error codes
This method may return the codes below. See Return codes and Capability errors for the full catalog.
Gateway and auth (SN / TK / OP)
| Code | Meaning | Next step |
|---|---|---|
SN1001 | Signature error | Check sign per Development specification |
TK1002 | Token invalid or expired | Refresh accessToken |
OP1002 | Missing required parameter | Add required fields |
OP1003 | Invalid parameter | Match this page’s parameter table |
OP1009 | Permission denied | Check token and device bind/share grants |
OP1013 | Total call limit exceeded | Reduce call rate |
OP1014 | Daily per-interface limit exceeded | See Interface call limits |
DV1007 | Device offline | Wait until the device is online |
See Return codes · OP/SN/TK for the full catalog.
Sub-accounts (SUB)
| Code | Meaning | Next step |
|---|---|---|
SUB1001–SUB1002 | Sub-account lacks API permission | Update policy via addPolicy |
SUB1005 | Sub-account token expired | Refresh subAccountToken |
SUB1006 | No device grant for sub-account | Check Resource and device serial |
SUB1008 | Sub-account not bound to app | Create and bind the sub-account first |
See Return codes · SUB.
