This page shows how to generate a token on your server for Agora SDK versions 2.1.0+. The token is used for joining a channel.

The following programming languages are covered. Choose the one that applies to you:

  • Java
  • C++
  • Python
  • Go
  • PHP
  • Node.js

Agora does not support signing Token with a non-zero string uid for the time being.

Java

Initializes the Token Builder

public boolean initTokenBuilder(String originToken);

This method uses the original token to reinitialize the token builder. This method enables the token builder to inherit the App ID, App Certificate, Channel Name, uid, and Privilege of the original token.

Do not call this method if you do not have an original token.

Name Description
originToken The original token.
Return value
  • true: Method call succeeded.
  • false: Method call failed.

Struct of the TokenBuilder

public SimpleTokenBuilder(String appId, String appCertificate, String channelName, String uid);

This method is the struct of SimpleTokenBuilder.

Name Description
App ID ID of the application that you registered in the Agora Dashboard. See Getting an App ID.
App Certificate Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate.
channelName Name of the channel that the user wants to join.
uid ID of the user who wants to join a channel.

Generates a Token (buildToken)

public String buildToken();

This method generates a token in the string format.

C++

Initializes the Token Builder

bool initTokenBuilder(const std::string& originToken);

This method uses the original token to reinitialize the token builder. This method enables the token builder to inherit the App ID, App Certificate, Channel Name, uid, and privilege of the original token.

Do not call this method if you do not have an original token.

Name Description
originToken The original token.
Return value
  • True: Method call succeeded.
  • False: Method call failed.

Struct of the TokenBuilder

SimpleTokenBuilder();
SimpleTokenBuilder(const std::string& appId, const std::string& appCertificate,
                   const std::string& channelName, uint32_t uid = 0);
SimpleTokenBuilder(const std::string& appId, const std::string& appCertificate,
                   const std::string& channelName, const std::string& uid = "");

This method is the struct of SimpleTokenBuilder.

Name Description
App ID ID of the application that you registered in the Agora Dashboard. See Getting an App ID.
App Certificate Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate.
channelName Name of the channel that the user wants to join.
uid ID of the user who wants to join a channel.

Generates a Token (buildToken)

std::string buildToken();

This method generates a token in the string format.

Python

Initializes the Token Builder

def initTokenBuilder(self, originToken);

This method uses the original token to reinitialize the token builder. This method enables the token builder to inherit the App ID, App Certificate, Channel Name, uid, and Privilege of the original token.

Do not call this method if you do not have an original token.

Name Description
originToken The original token.
Return value
  • 0: Method call succeeded.
  • <0: Method call failed.

Struct of the TokenBuilder

def __init__(self, appID, appCertificate, channelName, uid);

This method is the struct of SimpleTokenBuilder.

Name Description
App ID ID of the application that you registered in the Agora Dashboard. See Getting an App ID.
App Certificate Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate.
channelName Name of the channel that the user wants to join.
uid ID of the user who wants to join a channel.

Generates a Token (buildToken)

def buildToken(self);

This method generates a token in the string format.

Go

Initializes the Token Builder

func (builder SimpleTokenBuilder) InitTokenBuilder(originToken string);

This method uses the original token to reinitialize the token builder. This method enables the token builder to inherit the App ID, App Certificate, Channel Name, uid, and Privilege of the original token.

Do not call this method if you do not have an original token.

Name Description
originToken The original token.
Return value
  • 0: Method call succeeded.
  • <0: Method call failed.

Struct of the TokenBuilder

func CreateSimpleTokenBuilder(appID, appCertificate, channelName string, uid uint32) SimpleTokenBuilder;

This method is the struct of SimpleTokenBuilder.

Name Description
App ID ID of the application that you registered in the Agora Dashboard. See Getting an App ID.
App Certificate Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate.
channelName Name of the channel that the user wants to join.
uid ID of the user who wants to join a channel.

Generates a Token (buildToken)

func (builder SimpleTokenBuilder) BuildToken() (string,error);

This method generates a token in the string format.

PHP

Initializes the Token Builder

function initTokenBuilder($originToken);

This method uses the original token to reinitialize the token builder. This method enables the token builder to inherit the App ID, App Certificate, Channel Name, uid, and Privilege of the original token.

Do not call this method if you do not have an original token.

Name Description
originToken The original token.
Return value
  • 0: Method call succeeded.
  • <0: Method call failed.

Struct of the TokenBuilder

public function __construct($appID, $appCertificate, $channelName, $uid);

This method is the struct of SimpleTokenBuilder.

Name Description
App ID ID of the application that you registered in the Agora Dashboard. See Getting an App ID.
App Certificate Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate.
channelName Name of the channel that the user wants to join.
uid ID of the user who wants to join a channel.

Generates a Token (buildToken)

public function buildToken();

This method generates a token in the string format.

Node.js

Initializes the Token Builder

initTokenBuilder = function (originToken);

This method uses the original token to reinitialize the token builder. Once called, this method enables the token builder to inherit the App ID, App Certificate, Channel Name, uid, and Privilege of the original token.

Do not call this method if you do not have an original token.

Name Description
originToken The original token.
Return value
  • 0: Method call succeeded.
  • <0: Method call failed.

Struct of the TokenBuilder

var SimpleTokenBuilder = function (appID, appCertificate, channelName, uid);

This method is the struct of SimpleTokenBuilder.

Name Description
App ID ID of the application that you registered in the Agora Dashboard. See Getting an App ID.
App Certificate Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate.
channelName Name of the channel that the user wants to join.
uid ID of the user who wants to join a channel.

Generates a Token (buildToken)

this.buildToken = function ();

This method generates a token in the string format.