Skip to main content

Access token

An access token is a short-lived token that allows applications to use PlanetKit. An application generates and returns an access token from the app server.

Access token authentication flow

The authentication flow using an access token is as follows:

  1. An app client requests an access token to the app server using the communication channel defined by the application. Note that this channel is not provided by LINE Planet.
  2. The app server generates an access token and sends it to the app client.
  3. The app client sets the access token in PlanetKit by initializing a call parameter or conference parameter with the access token.
  4. The app client makes a call using the call parameter or joins a conference using the conference parameter.

The following diagram shows the authentication flow using an access token:

Access token flow

Access token format

The access token is a JSON WebToken (JWT). A JWT is an encoded JSON object consisting of a header, payload, and signature.

# JWT example
eyJ*****************.eyJ*********.*******************************************

The header typically consists of two parts.

  • Token type (typ): JWT
  • Signing algorithm (alg): HS256
# Header example
# eyJ*********************************
{
"typ": "JWT",
"alg": "HS256"
}

Payload

# Payload example
# eyJ*****************************************************************************************************************************************************************************************************************************************************
{
"sub": "YOUR_SERVICE_ID",
"uid": "2048",
"iss": "YOUR_API_KEY",
"iat": 1617636530
}

Signature

The signature part is not a JSON object. An API secret is used to create the signature part.

# Signature example
# *********-*********-***********************
HMACSHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), API-secret)

How to generate access tokens

Prerequisites

To generate an access token, you must have API key and API secret. Refer to Generating an API key to generate an API key.

Create an access token

Create an access token in the app server.

Note

Do not create access tokens in your app client.

As mentioned earlier, a JWT is an encoded JSON object consisting of a header, payload, and signature. To generate an access token, you must set appropriate values for each part. The following table shows which values should be used.

JWT headerDescriptionValue
typToken type. Must be "JWT".JWT
algSigning algorithm. Must use HS256.HS256
JWT payloadDescriptionExample
subService IDYOUR_SERVICE_ID
uidUser ID1122
issAPI key****************************
iatCreation time in seconds1615740516
Note

To prevent increasing the size of access tokens, do not add payload values other than the JWT parameters shown above.

Create an access token code example - Java

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

public class AccessTokenGenerator {
public static void main(String[] args) {
String serviceId = "YOUR_SERVICE_ID";
String userId = "2048";
String apiKey = "YOUR_API_KEY";
String apiSecret = "YOUR_API_SECRET";

Map<String, Object> header = new HashMap<>();
header.put("typ", "JWT");

Date issuedAt = new Date(System.currentTimeMillis());

Algorithm algo = Algorithm.HMAC256(apiSecret);
String token = JWT.create()
//header
.withHeader(header)
//payload
.withSubject(serviceId)
.withIssuer(apiKey)
.withIssuedAt(issuedAt)
.withClaim("uid", userId)
//signature
.sign(algo);

System.out.println(token);
// eyJ*********************************.eyJ****************************************************************************************************************.***********-*******************************
}
}

For examples in other programming languages, refer to JWT Libraries.