/v1/authorizations/cancelToken

POST /v1/authorizations/cancelToken

With this API call, a merchant can cancel the access token that is obtained from the response of the /v1/authorizations/applyToken API.

Note: After cancellation, the refresh token cannot be used even if it is valid.

Structure

A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:

Request parameters

Field

Data type

Required

Description

Example

accessToken

StringĀ 

Yes

The access token is used to access user information. For the specific information that can be accessed, see the my.getAuthCode JSAPI.

  • Maximum length: 128 characters
  • Characters not allowed: special characters such as @ # ?

Note: Obtained this field via the /v1/authorizations/applyToken API.

"281010033AB2F588D14B43238637264FCA5AAF35xxxx"

extendInfo

String

No

Indicates theĀ extended information about this API.

  • Maximum length: 4096 characters
  • Characters not allowed: special characters such as @ # ?
  • Can be Null.
copy
{
    "memo": "memo"
}

Response parameters

Field

Data type

Required

Description

Example

result

Result

Yes

Indicates the request result such as status and error codes.

copy
{
  "resultCode": "SUCCESS",
  "resultStatus": "S",
  "resultMessage": "success"
}

extendInfo

String

No

Indicates theĀ extended information about this API.

  • Maximum length: 4096 characters
  • Characters not allowed: special characters such as @ # ?
  • Can be Null.
copy
{
    "memo": "memo"
}

Result process logic

In the response, the result.resultStatus field indicates the result of processing a request. The following table describes each result status:

Result Status

DescriptionĀ 

S

The authorization is canceled successfully.

This means that authorized merchants can neither use access token to access user data nor use refresh token to obtain a new access token.

The corresponding result.resultCode is SUCCESS and theĀ result.resultMessageĀ is SUCCESS.

U

The statusĀ of the authorization cancellation is unknown.Ā 

The corresponding result.resultCode is UNKNOWN_EXCEPTIONĀ and result.resultMessage is "An API calling is failed, which is caused by unknown reasons.".

For details, see the Common error codes section.

F

The cancellation of authorization is failed. The authorized merchant may guide the user to try again.Ā 

The corresponding result.resultCodeĀ and result.resultMessage are various based on different situations.Ā For details, see the followingĀ Error codes section.

Error codes

Error codes are usually classified into the following categories:

  • Common error codes are common for all Mini Program OpenAPIs in V1. Ā 
  • API-specific error codes are listed in the following table.

Error code

Result status

Error message

Further action

INVALID_ACCESS_TOKEN

F

The access token is invalid.

Obtain a new access token with refresh token via the /v1/authorizations/applyToken API and then request to cancel the access token again.

EXPIRED_ACCESS_TOKEN

F

The access token is expired.

Obtain a new access token with refresh token via the /v1/authorizations/applyToken API and then request to cancel the access token again.

CANCELED_ACCESS_TOKEN

F

The access token is canceled.

Obtain a new access token with refresh token via the /v1/authorizations/applyToken API and then request to cancel the access token again.

Samples

The data flow to cancel an access token is illustrated as below:

cancelToken.png

  1. The user wants to cancel the authorization.
  2. The mini program sends the cancellation request to the merchant backend.
  3. The merchant backend calls this API to cancel the authorization with accessToken.
  4. Then the E-wallet backend processes the request and returns the cancellation result to the merchant server.
  5. The merchant backend returns the cancellation result to the mini program.
  6. Finally, the mini program will display the cancellation result to the user.

Request

copy
{
  "accessToken": "281010033AB2F588D14B43238637264FCA5AAF35xxxx"
}

The mini program sends a cancellation request to the merchant to cancel the access token (281010033AB2F588D14B43238637264FCA5AAF35xxxx).

Response

copy
{
  "result": {
    "resultCode":"SUCCESS",
    "resultStatus":"S",
    "resultMessage":"success"
  }
}

result.resultStatus is S, which means the request to cancel the access token is successful.

Related links

my.getAuthCode

/v1/authorizations/applyToken