HMS IAP Verify Token returning Token is Invalid or Expired

267 Views Asked by At

I am trying to validate my purchases(for now consumables). For this reason i am developing small server app. I found out this git package hms iap server demo

In DemoCofig script has need 2 variable ClientId, ClientSecret. I getted from app gallery connect dashboard from Project Settings->App Information. Dashboard Huawei

After pruchasing i am writing the console my purchase token which i getted InAppPurchaseData.PurchaseToken.

and i am requesting from my server to IAP Server. It always returning:

"{\"responseCode\":\"6\",\"responseMessage\":\"Token is expired or invalid\"}"

Purchasing job is working on SandBox(Test), I am trying to reach : https://orders-at-dre.iap.dbankcloud.com.

I am not clearly understand which token is expired or invalid ? Access Token or my purchase token ?

1

There are 1 best solutions below

1
On BEST ANSWER
"{\"responseCode\":\"6\",\"responseMessage\":\"Token is expired or invalid\"}"

This interface prompts that the token is invalid or expired. Generally, the token is an AccessToken (the validity period is 1 hour, AT for short). The validity period of the purchaseToken is 30 days. (There is also a possibility of expiration, but it is much less likely than the former).

The possible causes are as follows:

  1. The AT has expired. In this case, the AT needs to be obtained again (high probability). API for Obtaining an App-Level Access Token

  2. Invalid AT format (medium probability)

Ensure that the format of the request body is correct when the AT is used as the request body.

The authentication information is specified based on the request header. The details are as follows:

Authentication information is specified based on the request header: App-level access token: Authorization: Basic Base64(APPAT:atvalue)

  • Example: The app-level access token is thisIsAppAtValue, then APPAT:atvalue is APPAT:thisIsAppAtValue.

    Therefore, replace APPAT:atvalue in Base64(APPAT:atvalue) with "APPAT:thisIsAppAtValue" to generate value QVBQQVQ6dGhpc0lzQXBwQXRWYWx1ZQ==.

    The value of Authorization in the request header is as follows: Basic QVBQQVQ6dGhpc0lzQXBwQXRWYWx1ZQ==

    For details check this docs.

  1. The purchaseToken does not match the appID (low probability).

  2. Site request error (low probability)

You can also refer to this forum similar questions, but it is in Chinese, you can translate it.