Generate token using an app server
Interactive Whiteboard uses a set of tokens for user authentication: SDK Tokens, Room Tokens, and Task Tokens. Each type of token can be assigned to an admin, writer, or reader role. For details, see Token Overview.
Agora provides an open source netless-token repository on GitHub that includes code samples for generating tokens using JavaScript, TypeScript, Java, Golang,  PHP,  Ruby, and  C#.
This article introduces how to generate tokens from your app server using these code samples and your access keys (the AK and SK).
To enhance security, do not save or send the AK and SK to your app clients. You should save the AK and SK on the app server, and issue tokens from the app server according to the actual needs of your app scenarios.
Ensure that you have enabled Interactive Whiteboard for your Agora Console project.
In the netless-token-master/Node/JavaScript folder, you can find:
- An index.jsfile, which contains the source code for generating tokens.
- A README.mdfile, which contains code samples for generating tokens.
Before proceeding, ensure that you have installed the latest version of Node.js LTS.
Refer to the following steps to generate an SDK Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Node/JavaScriptfolder and run the following command to install Node.js dependencies:
 
- Create a file named sdktoken.jsand copy the following code into it:
_11const  { sdkToken, TokenPrefix } = require("./index");
 _11// Generate a SDK Token
 _11const netlessSDKToken = sdkToken(
 _11   "Your AK", // Fill in the AK you get from Agora Console 
 _11   "Your SK", // Fill in the SK you get from Agora Console
 _11   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _11       role: 0 // Define the permissions granted by the token. You can set it to 0 (Admin), 1 (Writer), or 2 (Reader) 
 _11console.log(netlessSDKToken)
 
- Run the following command, after which you should see a token prefixed with NETLESSSDK_in the terminal:
Refer to the following steps to generate a Room Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Node/JavaScriptfolder and run the following command to install Node.js dependencies:
 
- Create a file named roomtoken.jsand copy the following code into it:
_12const  { roomToken, TokenPrefix } = require("./index");
 _12// Generate a Room token
 _12const netlessRoomToken = roomToken(
 _12  "Your AK", // Fill in the AK you get from Agora Console 
 _12  "Your SK", // Fill in the SK you get from Agora Console
 _12  1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _12      role: 1 // Define the permissions granted by the token. You can set it to 0 (Admin), 1 (Writer), or 2 (Reader) 
 _12      uuid: "Room UUID" // Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list 
 _12console.log(netlessRoomToken)
 
- Run the following command, after which you should see a token prefixed with NETLESSROOM_in the terminal:
Refer to the following steps to generate a Task Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Node/JavaScriptfolder and run the following command to install Node.js dependencies:
 
- Create a file named tasktoken.js, and copy the following code into it:
_12const  { taskToken, TokenPrefix } = require("./index");
 _12// Generate a Task Token
 _12const netlessTaskToken = taskToken(
 _12   "Your AK", // Fill in the AK you get from Agora Console 
 _12   "Your SK", // Fill in the SK you get from Agora Console
 _12   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _12       role: 1 // Define the permissions granted by the token. You can set it to 0 (Admin), 1 (Writer), or 2 (Reader) 
 _12       uuid: "Task UUID" // Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task 
 _12console.log(netlessTaskToken)
 
- Run the following command, after which you should see a token prefixed with NETLESSTASK_in the terminal:
In the netless-token-master/Node/TypeScript folder, you can find:
- A src/index.tsfile, which contains the source code for generating Tokens.
- A README.mdfile, which contains code samples for generating tokens.
Before proceeding, ensure that you have installed the latest version of Node.js LTS.
Refer to the following steps to generate an SDK Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Node/TypeScriptfolder and run the following command to install TypeScript:
 
_1npm install -g typescript
 
- Create a file named sdktoken.tsand copy the following code into it:
_10import { sdkToken, TokenPrefix } from "./src/index";
 _10const netlessSDKToken = sdkToken(
 _10   "Your AK", // Fill in the AK you get from Agora Console 
 _10   "Your SK", // Fill in the SK you get from Agora Console
 _10   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _10       role: TokenRole.Admin // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _10console.log(netlessSDKToken)
 
- Run the following command to generate the corresponding sdktoken.jsfile:
- Run the following command, after which you should see a token prefixed with NETLESSSDK_in the terminal:
Refer to the following steps to generate a Room Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Node/TypeScriptfolder and run the following command to install TypeScript:
 
_1npm install -g typescript
 
- Create a file named roomtoken.tsand copy the following code into it:
_11import { roomToken, TokenPrefix } from "./src/index";
 _11const netlessRoomToken = roomToken(
 _11   "Your AK", // Fill in the AK you get from Agora Console 
 _11   "Your SK", // Fill in the SK you get from Agora Console
 _11   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _11       role: TokenRole.Admin // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _11       uuid: "Room UUID" // Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list 
 _11console.log(netlessRoomToken)
 
- Run the following command to generate the corresponding roomtoken.jsfile:
- Run the following command, after which you should see a token prefixed with NETLESSROOM_in the terminal:
Refer to the following steps to generate a Task Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Node/TypeScriptfolder and run the following command to install TypeScript:
 
_1npm install -g typescript
 
- Create a file named tasktoken.tsand copy the following code into it:
_11import { taskToken, TokenPrefix } from "./src/index";
 _11const netlessTaskToken = taskToken(
 _11   "Your AK", // Fill in the AK you get from Agora Console 
 _11   "Your SK", // Fill in the SK you get from Agora Console
 _11   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _11           role: TokenRole.Writer // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _11           uuid: "Task UUID" // Fill in the Task UUID. You can get it by calling the RESTful API to start a file conversion task 
 _11console.log(netlessTaskToken)
 
- Run the following command to generate the corresponding tasktoken.jsfile:
- Run the following command, after which you should see a token prefixed with NETLESSTASK_in the terminal:
In the netless-token-master/Java folder, you can find:
- A Token.javafile, which contains the source code for generating tokens.
- A README.mdfile, which contains code samples for generating tokens.
Before proceeding, ensure that you have installed a Java Development Kit.
Refer to the following steps to generate an SDK Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Javafolder and add the following code to theToken.javafile:
 
_13public static void main(String[] args) throws Exception {
 _13   Map<String, String> map = new HashMap<>();
 _13      // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _13      map.put("role", Token.TokenRole.Admin.getValue());
 _13      String sdkToken = Token.sdkToken(
 _13       "Your AK", // Fill in the AK you get from Agora Console 
 _13       "Your SK", // Fill in the SK you get from Agora Console  
 _13	   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _13      System.out.println(sdkToken);
 
- Go to the directory of the Token.javafile and run the following command:
- Run the following command, after which you should see a token prefixed with NETLESSSDK_in the terminal:
Refer to the following steps to generate a Room Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Javafolder and add the following code to theToken.javafile:
 
_15public static void main(String[] args) throws Exception {
 _15   Map<String, String> map = new HashMap<>();
 _15      // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _15      map.put("role", Token.TokenRole.Reader.getValue());
 _15      // Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list 
 _15      map.put("uuid", "Your Room UUID");
 _15      String roomToken = Token.roomToken(
 _15       "Your AK", // Fill in the AK you get from Agora Console 
 _15       "Your SK", // Fill in the SK you get from Agora Console  
 _15	   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _15      System.out.println(roomToken);
 
- Go to the directory of the Token.javafile and run the following command:
- Run the following command, after which you should see a token prefixed with NETLESSROOM_in the terminal:
Refer to the following steps to generate a Task Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/Javafolder and add the following code to theToken.javafile:
 
_15public static void main(String[] args) throws Exception {
 _15   Map<String, String> map = new HashMap<>();
 _15      // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _15      map.put("role", Token.TokenRole.Writer.getValue());
 _15      // Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task 
 _15      map.put("uuid", "Your Task UUID");
 _15      String taskToken = Token.taskToken(
 _15       "Your AK", // Fill in the AK you get from Agora Console 
 _15       "Your SK", // Fill in the SK you get from Agora Console  
 _15	   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _15      System.out.println(taskToken);
 
- Go to the directory of the Token.javafile and run the following command:
- Run the following command, after which you should see a token prefixed with NETLESSTASK_in the terminal:
In the netless-token-master/golang folder, you can find:
- A Token.gofile, which contains the source code for generating tokens.
- A README.mdfile, which contains code samples for generating tokens.
Before proceeding, ensure that you have installed the latest version of Golang.
Refer to the following steps to generate an SDK Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Create a file named sdktoken.goand copy the following code into it:
 
_18   "../golang" // Replace ../golang with the path to the netless-token folder in your local directory 
 _18   c := token.SDKContent{
 _18       // Define the permissions granted by the token. You can set it to token.AdminRole, token.ReaderRole, or token.WriterRole 
 _18       Role: token.AdminRole,
 _18   netlessSDKToken := token.SDKToken(
 _18       "Your AK", // Fill in the AK you get from Agora Console 
 _18       "Your SK", // Fill in the SK you get from Agora Console  
 _18	   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _18    fmt.Println(netlessSDKToken)
 
- Go to the directory of the sdktoken.gofile and run the following command, after which you should see a token prefixed withNETLESSSDK_in the terminal:
Refer to the following steps to generate a Room Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Create a file named roomtoken.goand copy the following code into it:
 
_20   "../golang" // Replace ../golang with the path to the netless-token folder in your local directory 
 _20   c := token.RoomContent{
 _20       // Define the permissions granted by the token. You can set it to token.AdminRole, token.ReaderRole, or token.WriterRole 
 _20       Role: token.AdminRole,
 _20       // Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list 
 _20       Uuid: "Your Room UUID",
 _20   netlessRoomToken := token.RoomToken(
 _20       "Your AK", // Fill in the AK you get from Agora Console 
 _20       "Your SK", // Fill in the SK you get from Agora Console  
 _20	   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _20    fmt.Println(netlessRoomToken)
 
- Go to the directory of the roomtoken.gofile and run the following command, after which you should see a token prefixed withNETLESSROOM_in the terminal:
Refer to the following steps to generate a Task Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Create a file named tasktoken.goand copy the following code into it:
 
_20   "../golang" // Replace ../golang with the path to the netless-token folder in your local directory 
 _20   c := token.TaskContent{
 _20       // Define the permissions granted by the token. You can set it to token.AdminRole, token.ReaderRole, or token.WriterRole 
 _20       Role: token.WriterRole,
 _20       // Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task 
 _20   netlessTaskToken := token.TaskToken(
 _20       "Your AK", // Fill in the AK you get from Agora Console 
 _20       "Your SK", // Fill in the SK you get from Agora Console  
 _20	   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _20    fmt.Println(netlessTaskToken)
 
- Go to the directory of the tasktoken.gofile and run the following command, after which you should see a token prefixed withNETLESSTASK_in the terminal:
In the netless-token-master/php folder, you can find:
- A Generate.phpfile, which contains the source code for generating tokens.
- A README.mdfile, which contains code samples for generating tokens.
Before proceeding, ensure that you have installed PHP 7.3 or later.
Refer to the following steps to generate an SDK Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/phpfolder, create a file namedsdktoken.php, and copy the following code into it:
 
_14// Import Composer to manage dependencies 
 _14require __DIR__ . '/vendor/autoload.php';
 _14use Netless\Token\Generate;
 _14$netlessToken = new Generate;
 _14$sdkToken = $netlessToken->sdkToken(
 _14   "Your AK", // Fill in the AK you get from Agora Console 
 _14   "Your SK", // Fill in the SK you get from Agora Console  
 _14   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _14       "role" => Generate::AdminRole, // Define the permissions granted by the token. You can set it to AdminRole, WriterRole, or ReaderRole 
 
- Run the following command, after which you should see a token prefixed with NETLESSSDK_in the terminal:
Refer to the following steps to generate a Room Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/phpfolder, create a file namedroomtoken.php, and copy the following code into it:
 
_15// Import Composer to manage dependencies 
 _15require __DIR__ . '/vendor/autoload.php';
 _15use Netless\Token\Generate;
 _15$netlessToken = new Generate;
 _15$roomToken = $netlessToken->roomToken(
 _15   "Your AK", // Fill in the AK you get from Agora Console 
 _15   "Your SK", // Fill in the SK you get from Agora Console  
 _15   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _15       "role" => Generate::ReaderRole, // Define the permissions granted by the token. You can set it to AdminRole, WriterRole, or ReaderRole 
 _15       "uuid" => "Your Room UUID" // Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list 
 
- Run the following command, after which you should see a token prefixed with NETLESSROOM_in the terminal:
Refer to the following steps to generate a Task Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/phpfolder, create a file namedtasktoken.php, and copy the following code into it:
 
_15// Import Composer to manage dependencies 
 _15require __DIR__ . '/vendor/autoload.php';
 _15use Netless\Token\Generate;
 _15$netlessToken = new Generate;
 _15$roomToken = $netlessToken->roomToken(
 _15   "Your AK", // Fill in the AK you get from Agora Console 
 _15   "Your SK", // Fill in the SK you get from Agora Console  
 _15   1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _15       "role" => Generate::ReaderRole, // Define the permissions granted by the token. You can set it to AdminRole, WriterRole, or ReaderRole 
 _15              "uuid" => "Your Task UUID" // Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task 
 
- Run the following command, after which you should see a token prefixed with NETLESSTASK_in the terminal:
In the netless-token-master/ruby folder, you can find:
- A token.rbfile, which contains the source code for generating tokens.
- A README.mdfile, which contains code samples for generating tokens.
Before proceeding, ensure that you have installed Ruby 2.1 or later.
Refer to the following steps to generate an SDK Token:
- 
Download the netless-token repository, or clone it to a local directory. 
- 
Go to the netless-token-master/rubyfolder and run the following command to installuuidtools:
 
- In the rubyfolder, create a file namedsdktoken.rband copy the following code into it:
_10require './lib/token.rb'
 _10sdktoken = NetlessToken.sdk_token(
 _10   "Your AK", # Fill in the AK you get from Agora Console 
 _10   "Your SK", # Fill in the SK you get from Agora Console  
 _10   1000 * 60 * 10, # Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _10       :role => NetlessToken::ROLE::ADMIN # Define the permissions granted by the token. You can set it to ADMIN, WRITER, or READER 
 
- Run the following command, after which you should see a token prefixed with NETLESSSDK_in the terminal:
Refer to the following steps to generate a Room Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/rubyfolder and run the following command to installuuidtools:
 
- In the rubyfolder, create a file namedroomtoken.rband copy the following code into it:
_11require './lib/token.rb'
 _11roomtoken = NetlessToken.room_token(
 _11   "Your AK", # Fill in the AK you get from Agora Console 
 _11   "Your SK", # Fill in the SK you get from Agora Console  
 _11   1000 * 60 * 10, # Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _11       :role => NetlessToken::ROLE::ADMIN # Define the permissions granted by the token. You can set it to ADMIN, WRITER, or READER 
 _11       :uuid => "Your Room UUID" # Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list 
 
- Run the following command, after which you should see a token prefixed with NETLESSROOM_in the terminal:
Refer to the following steps to generate a Task Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/rubyfolder, and run the following command to installuuidtools:
 
- In the rubyfolder, create a file namedtasktoken.rband copy the following code into it:
_11require './lib/token.rb'
 _11tasktoken = NetlessToken.task_token(
 _11   "Your AK", # Fill in the AK you get from Agora Console 
 _11   "netless sk", # Fill in the SK you get from Agora Console  
 _11   1000 * 60 * 10, # Token validity period in milliseconds. If you set it to 0, the token will never expire 
 _11       :role => NetlessToken::ROLE::ADMIN # Define the permissions granted by the token. You can set it to ADMIN, WRITER, or READER 
 _11       :uuid => "Your Room UUID" # Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task 
 
- Run the following command, after which you should see a token prefixed with NETLESSTASK_in the terminal:
In the netless-token-master/csharp folder, you can find:
- A Token.csfile, which contains the source code for generating tokens.
- A README.mdfile, which contains code samples for generating tokens.
Before proceeding, ensure that you have installed the latest version of Visual Studio.
Refer to the following steps to generate an SDK Token:
- 
Download the netless-token repository, or clone it to a local directory. 
- 
Go to the netless-token-master/csharpfolder and open thecsharp.slnfile in Visual Studio.
 
- 
Fill in your AK, SK, token validity period, and token role in the Program.csfile.
 
_18 static void Main(string[] args)
 _18     string token = NetlessToken.SdkToken(
 _18         // Fill in the AK you get from Agora Console
 _18         // Fill in the SK you get from Agora Console
 _18         // Set the Token validity period. If you set it to 0, the token will never expire 
 _18         // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _18         new SdkContent(TokenRole.Admin)); 
 _18     Console.WriteLine(token);
 
- Run the project in Visual Studio. You should see a token prefixed with NETLESSSDK_in the terminal.
Refer to the following steps to generate a Room Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/csharpfolder and open thecsharp.slnfile in Visual Studio.
 
- 
Delete the code in the Program.csfile and copy the following sample code into it:
 
_20 static void Main(string[] args)
 _20     string token = NetlessToken.RoomToken(
 _20         // Fill in the AK you get from Agora Console 
 _20         // Fill in the SK you get from Agora Console 
 _20         // Set the Token validity period. If you set it to 0, the token will never expire
 _20         // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _20         // Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list 
 _20         new RoomContent(TokenRole.Admin, "房间的 UUID")
 _20     Console.WriteLine(token);
 
- Run the project in Visual Studio. You should see a token prefixed with NETLESSROOM_in the terminal.
Refer to the following steps to generate a Task Token:
- 
Download the netless-token repository or clone it to a local directory. 
- 
Go to the netless-token-master/csharpfolder and open thecsharp.slnfile in Visual Studio.
 
- 
Delete the code in the Program.csfile and copy the following sample code into it:
 
_20 static void Main(string[] args)
 _20     string token = NetlessToken.RoomToken(
 _20         // Fill in the AK you get from Agora Console 
 _20         // Fill in the SK you get from Agora Console 
 _20         // Set the Token validity period. If you set it to 0, the token will never expire
 _20         // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader 
 _20         // Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task 
 _20         new TaskContent(TokenRole.Admin, "Your Task UUID")
 _20     Console.WriteLine(token);
 
- Run the project in Visual Studio. You should see a token prefixed with NETLESSTASK_in the terminal.