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.js file, which contains the source code for generating tokens. 
- A 
README.md file, 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/JavaScript folder and run the following command to install Node.js dependencies:
 
- Create a file named 
sdktoken.js and 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/JavaScript folder and run the following command to install Node.js dependencies:
 
- Create a file named 
roomtoken.js and 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/JavaScript folder 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.ts file, which contains the source code for generating Tokens. 
- A 
README.md file, 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/TypeScript folder and run the following command to install TypeScript:
 
_1npm install -g typescript
 
 
- Create a file named 
sdktoken.ts and 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.js file: 
- 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/TypeScript folder and run the following command to install TypeScript:
 
_1npm install -g typescript
 
 
- Create a file named 
roomtoken.ts and 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.js file: 
- 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/TypeScript folder and run the following command to install TypeScript:
 
_1npm install -g typescript
 
 
- Create a file named 
tasktoken.ts and 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.js file: 
- 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.java file, which contains the source code for generating tokens. 
- A 
README.md file, 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/Java folder and add the following code to the Token.java file:
 
_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.java file 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/Java folder and add the following code to the Token.java file:
 
_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.java file 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/Java folder and add the following code to the Token.java file:
 
_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.java file 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.go file, which contains the source code for generating tokens. 
- A 
README.md file, 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.go and 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.go file and 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.
 
- 
Create a file named roomtoken.go and 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.go file and 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.
 
- 
Create a file named tasktoken.go and 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.go file and run the following command, after which you should see a token prefixed with NETLESSTASK_ in the terminal: 
In the netless-token-master/php folder, you can find:
- A 
Generate.php file, which contains the source code for generating tokens. 
- A 
README.md file, 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/php folder, create a file named sdktoken.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/php folder, create a file named roomtoken.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/php folder, create a file named tasktoken.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.rb file, which contains the source code for generating tokens. 
- A 
README.md file, 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/ruby folder and run the following command to install uuidtools:
 
- In the 
ruby folder, create a file named sdktoken.rb and 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/ruby folder and run the following command to install uuidtools:
 
- In the 
ruby folder, create a file named roomtoken.rb and 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/ruby folder, and run the following command to install uuidtools:
 
- In the 
ruby folder, create a file named tasktoken.rb and 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.cs file, which contains the source code for generating tokens. 
- A 
README.md file, 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/csharp folder and open the csharp.sln file in Visual Studio.
 
- 
Fill in your AK, SK, token validity period, and token role in the Program.cs file.
 
_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/csharp folder and open the csharp.sln file in Visual Studio.
 
- 
Delete the code in the Program.cs file 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/csharp folder and open the csharp.sln file in Visual Studio.
 
- 
Delete the code in the Program.cs file 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.