# Get Token

Access Token is a credential for calling digital human intelligent interactive services. This article describes how to obtain an access token.

# Preconditions

The appKey and appId have been obtained, which can be obtained in the session management of the digital person created.

##Steps

1、Generate signature by appKey and appId.

2、Use the signature to obtain the Token through the interface.

# signature generation

The signature uses the JWT mechanism, and the user can complete the signature by referring to the following

# Parameter Description

Signature generation requires the preparation of the following parameters

name type describe example
appId string Session ID, obtained after the session is created successfully xxxxxxx
appKey string Session key, obtained after the session is created successfully xxxxxxx
sigExp Integer Signature validity time, in seconds 1800

# demo code

The sample code of the signature is as follows, the Java version example

Introduce pom dependencies

<dependency>
    <groupId>com.auth0</groupId>
    <artifactId>java-jwt</artifactId>
    <version>3.8.3</version>
</dependency>
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import java.util.Calendar;
import java.util.Date;

public class SigUtils {
    /**
     * create signature
     *
     * @param appId  session appId
     * @param appKey session appKey
     * @param sigExp Signature valid time: in seconds
     * @return
     */
    public static String createSig(String appId, String appKey, int sigExp) {
        Calendar nowTime = Calendar.getInstance();
        nowTime.add(Calendar.SECOND, sigExp);
        Date expiresDate = nowTime.getTime();
        return JWT.create()
                //publish time
                .withIssuedAt(new Date())
                //effective time
                .withExpiresAt(expiresDate)
                //load
                .withClaim("appId", appId)
                //encryption
                .sign(Algorithm.HMAC256(appKey));
    }
}

# Get token by signature

Call the server interface to get the token

https://duix.guiji.ai/duix-manage-api/sdk/checkSig?sig={sig}

The return parameters are as follows:

name type describe example
appId string session appId xxxxxxx
token string session token xxxxxxx