Authentication

Token Authentication

When using the RESTful API to request services, you need to fill in the Token field in the HTTP request header for identity authentication.

The method of Token value generation is as follows::

  1. Log in to jocloud Management Background and select Personal Center.
  2. Click the account name in the upper right corner, select Interface Certificate from the drop-down menu to obtain the certificate ID and certificate key.
  3. The certificate ID and secret key are formed into a plainIDSecret string in the format of certificate ID: certificate secret key, and plainIDSecret is encoded by the Base64 algorithm to obtain the base64IDSecret string.
  4. Fill Base base64IDSecret in the token field of the HTTP request header.

Sample Code

The following is an example code for generating the token field in Java and Python.

Java

String restfulId = "qawsedrftg";        // your secret ID
String restfulSecret = "abcdefghijk";   // your secret key

// generate token
String plainIDSecret = restfulId + ":" + restfulSecret;
String base64IDSecret = new String(Base64.encodeBase64(plainIDSecret.getBytes("UTF-8")));

// Generate the request object and add the token information to the request header
Request request = new Request.Builder()
    .addHeader("token", "Base " + base64IDSecret)
    ...

Python

#!/usr/bin/python3
import requests
import base64

appid = 123456                 # your appid 
restful_id = 'qawsedrftg'      # your secret id
restful_secret = 'abcdefghijk' # your secret key

# http header
headers = {
    "content-type": "application/json"
}
# generate token
auth = base64.b64encode(("%s:%s" % (restful_id, restful_secret)).encode('utf-8'))
headers['token'] = 'Base ' + str(auth,'utf-8')

# request
url = "https://ai.jocloud.com/app/123456/v1/image/sync?traceId=bd526528-c0d7-4aa4-803b-f5a3fdc05805"
body = {}
res = requests.post(url, json=body, headers=headers)

Was this page helpful?

Helpful Not helpful
Submitted! Your feedback would help us improve the website.
Feedback
Top