Token Authentication API
This is the API for getting the Access Token.
Request Url
https://api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
https://sg-api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
https://my-api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
https://th-api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
https://ph-api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
https://mex-api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
https://col-api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
https://nga-api.advance.ai/openapi/auth/ticket/v1/generate-token
POST (application/json)
Request Parameters
Parameter | Description |
---|---|
accessKey |
|
timestamp |
|
signature |
|
periodSecond |
|
Note:
- You can find accessKey, secretKey on the Websaas Platform -> Account -> Account Management
- The timestamp in the “signature” must be consistent with parameter
timestamp
- Please remember to re-obtain a new valid token to do the authentication for the open APIs when the previous one is expired
Code Sample
curl -X POST \
-H "Content-Type: application/json" \
-d '{"accessKey":"22**70b","signature":"f786441e7b3d95f*****853a5a244f9522","timestamp":1648785145789,"periodSecond":120}' \
"https://api.advance.ai/openapi/auth/ticket/v1/generate-token"
Compute Signature Example
import java.security.MessageDigest;
public class SimpleSignature {
public static String generateSignature(String accessKey, String secretKey, String timestamp) {
try {
String combined = accessKey + secretKey + timestamp;
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(combined.getBytes("UTF-8"));
StringBuilder hex = new StringBuilder();
for (byte b : hash) {
String h = Integer.toHexString(0xff & b);
if (h.length() == 1) hex.append('0');
hex.append(h);
}
return hex.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
String accessKey = "sampleaccesskey";
String secretKey = "samplesecretkey";
String timestamp = "1665993522952";
String signature = generateSignature(accessKey, secretKey, timestamp);
System.out.println("Combined: " + accessKey + secretKey + timestamp);
// Expected output: 02209bbeaf0d0a3dd587f6a1ba22f84c98d142e3b545e77db7e4906ca56349f5
System.out.println("Encrypted: " + signature);
}
}
Response Description
Parameter | Description |
---|---|
code | Response Status Code |
message | Message returned from server |
data | token AccessToken |
expiredTime Expiration timestamp | |
extra | Extra response info such as exception message |
transactionId | the request id, the max length is 64 |
pricingStrategy | Deprecated , Always return FREE |
Response Code
Status Code | Message |
---|---|
SUCCESS | OK |
PARAMETER_ERROR | Timestamp error |
Parameter should not be empty | |
Signature error | |
ACCOUNT_DISABLED | Account Disabled |
CLIENT_ERROR | HTTP 400 - Bad Request |
Response Examples
SUCCESS
{
"code":"SUCCESS",
"message":"OK",
"data":{
"token":"eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJoNV9saXZlbmVzcyIsInN1YiI6IntcImN1c3RvbWVySWRcIjo1NTAwMDI4MixcImFjY291bnRJZFwiOjU1MDAwMjg0LFwicmVhbElwXCI6XCI0NS4yNTEuMTA3LjExMVwifSIsImF1ZCI6IldFQiIsImlhdCI6MTY0MjU4MDA3MiwiZXhwIjoxNjQyNTgwMTkyfQ.HmIDcuSW67A59x7bnumjGp0Wdcz-FmoDrnHF1YGui6wVPfulLn4Izonay5LQnySgph1dbyC1E0LtifS-BJo8VA",
"expiredTime":1642580192430
},
"extra":null,
"transactionId":"6c2c50a3049ce67e",
"pricingStrategy":"FREE"
}
PARAMETER_ERROR
{
"code":"PARAMETER_ERROR",
"message":"Parameter should not be empty",
"data":null,
"extra":null,
"transactionId":"040e769e38f87e3e",
"pricingStrategy":"FREE"
}
{
"code":"PARAMETER_ERROR",
"message":"Timestamp error",
"data":null,
"extra":null,
"transactionId":"a9c2a6c199ad5db5",
"pricingStrategy":"FREE"
}
{
"code":"PARAMETER_ERROR",
"message":"Signature error",
"data":null,
"extra":null,
"transactionId":"00b05cb9cf6f0fed",
"pricingStrategy":"FREE"
}
ACCOUNT_DISABLED
{
"code":"ACCOUNT_DISABLED",
"message":"Account Disabled",
"data":null,
"extra":null,
"transactionId":"5e00fded1272490e",
"pricingStrategy":"FREE"
}
CLIENT_ERROR
{
"code":"CLIENT_ERROR",
"message":"HTTP 400 - Bad Request",
"data":null,
"extra":null,
"transactionId":"bd5d5653c45d4c6e",
"pricingStrategy":"FREE"
}
Updated 6 days ago