Agora 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).
Ensure that you have enabled the whiteboard service for your Agora Console project.
In the netless-token-master/Node/JavaScript
folder, you can find:
index.js
file, which contains the source code for generating tokens.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:
npm install
sdktoken.js
, and copy the following code into it:const { sdkToken, TokenPrefix } = require("./index");
// Generate a SDK Token
const netlessSDKToken = sdkToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
{
role: 0 // Define the permissions granted by the token. You can set it to 0 (Admin), 1 (Writer), or 2 (Reader)
}
);
console.log(netlessSDKToken)
NETLESSSDK_
in the terminal:node sdktoken.js
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:
npm install
roomtoken.js
, and copy the following code into it:const { roomToken, TokenPrefix } = require("./index");
// Generate a Room token
const netlessRoomToken = roomToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
{
role: 1 // Define the permissions granted by the token. You can set it to 0 (Admin), 1 (Writer), or 2 (Reader)
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
}
);
console.log(netlessRoomToken)
NETLESSROOM_
in the terminal:node roomtoken.js
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:
npm install
tasktoken.js
, and copy the following code into it:const { taskToken, TokenPrefix } = require("./index");
// Generate a Task Token
const netlessTaskToken = taskToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
{
role: 1 // Define the permissions granted by the token. You can set it to 0 (Admin), 1 (Writer), or 2 (Reader)
uuid: "Task UUID" // Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task
}
);
console.log(netlessTaskToken)
NETLESSTASK_
in the terminal:node tasktoken.js
In the netless-token-master/Node/TypeScript
folder, you can find:
src/index.ts
file, which contains the source code for generating Tokens.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:
npm install -g typescript
sdktoken.ts
, and copy the following code into it:import { sdkToken, TokenPrefix } from "./src/index";
const netlessSDKToken = sdkToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
{
role: TokenRole.Admin // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
}
);
console.log(netlessSDKToken)
sdktoken.js
file:tsc sdktoken.ts
NETLESSSDK_
in the terminal:node sdktoken.js
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:
npm install -g typescript
roomtoken.ts
, and copy the following code into it:import { roomToken, TokenPrefix } from "./src/index";
const netlessRoomToken = roomToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
{
role: TokenRole.Admin // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
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
}
);
console.log(netlessRoomToken)
roomtoken.js
file:tsc roomtoken.ts
NETLESSROOM_
in the terminal:node roomtoken.js
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:
npm install -g typescript
tasktoken.ts
, and copy the following code into it:import { taskToken, TokenPrefix } from "./src/index";
const netlessTaskToken = taskToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
{
role: TokenRole.Writer // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
uuid: "Task UUID" // Fill in the Task UUID. You can get it by calling the RESTful API to start a file conversion task
}
);
console.log(netlessTaskToken)
tasktoken.js
file:tsc tasktoken.ts
NETLESSTASK_
in the terminal:node tasktoken.js
In the netless-token-master/Java
folder, you can find:
Token.java
file, which contains the source code for generating Tokens.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:
public static void main(String[] args) throws Exception {
Map<String, String> map = new HashMap<>();
// Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
map.put("role", Token.TokenRole.Admin.getValue());
String sdkToken = Token.sdkToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
map);
System.out.println(sdkToken);
}
Token.java
file, and run the following command:javac Token.java
NETLESSSDK_
in the terminal:java Token
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:
public static void main(String[] args) throws Exception {
Map<String, String> map = new HashMap<>();
// Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
map.put("role", Token.TokenRole.Reader.getValue());
// Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list
map.put("uuid", "Your Room UUID");
String roomToken = Token.roomToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
map);
System.out.println(roomToken);
}
Token.java
file, and run the following command:javac Token.java
NETLESSROOM_
in the terminal:java Token
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:
public static void main(String[] args) throws Exception {
Map<String, String> map = new HashMap<>();
// Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
map.put("role", Token.TokenRole.Writer.getValue());
// Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task
map.put("uuid", "Your Task UUID");
String taskToken = Token.taskToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
map);
System.out.println(taskToken);
}
Token.java
file, and run the following command:javac Token.java
NETLESSTASK_
in the terminal:java Token
In the netless-token-master/golang
folder, you can find:
Token.go
file, which contains the source code for generating tokens.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:
package main
import (
"fmt"
"../golang" // Replace ../golang with the path to the netless-token folder in your local directory
)
func main() {
c := token.SDKContent{
// Define the permissions granted by the token. You can set it to token.AdminRole, token.ReaderRole, or token.WriterRole
Role: token.AdminRole,
}
netlessSDKToken := token.SDKToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
&c,
)
fmt.Println(netlessSDKToken)
}
sdktoken.go
file, and run the following command, after which you should see a token prefixed with NETLESSSDK_
in the terminal:go sdktoken.go
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:
package main
import (
"fmt"
"../golang" // Replace ../golang with the path to the netless-token folder in your local directory
)
func main() {
c := token.RoomContent{
// Define the permissions granted by the token. You can set it to token.AdminRole, token.ReaderRole, or token.WriterRole
Role: token.AdminRole,
// Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list
Uuid: "Your Room UUID",
}
netlessRoomToken := token.RoomToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
&c,
)
fmt.Println(netlessRoomToken)
}
roomtoken.go
file, and run the following command, after which you should see a token prefixed with NETLESSROOM_
in the terminal:go roomtoken.go
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:
package main
import (
"fmt"
"../golang" // Replace ../golang with the path to the netless-token folder in your local directory
)
func main() {
c := token.TaskContent{
// Define the permissions granted by the token. You can set it to token.AdminRole, token.ReaderRole, or token.WriterRole
Role: token.WriterRole,
// Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task
Uuid: "Task UUID",
}
netlessTaskToken := token.TaskToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
&c,
)
fmt.Println(netlessTaskToken)
}
tasktoken.go
file, and run the following command, after which you should see a token prefixed with NETLESSTASK_
in the terminal:go tasktoken.go
In the netless-token-master/php
folder, you can find:
Generate.php
file, which contains the source code for generating tokens.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:
<?php
// Import Composer to manage dependencies
require __DIR__ . '/vendor/autoload.php';
use Netless\Token\Generate;
$netlessToken = new Generate;
$sdkToken = $netlessToken->sdkToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
array(
"role" => Generate::AdminRole, // Define the permissions granted by the token. You can set it to AdminRole, WriterRole, or ReaderRole
)
);
echo $sdkToken;
NETLESSSDK_
in the terminal:php sdktoken.php
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:
<?php
// Import Composer to manage dependencies
require __DIR__ . '/vendor/autoload.php';
use Netless\Token\Generate;
$netlessToken = new Generate;
$roomToken = $netlessToken->roomToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
array(
"role" => Generate::ReaderRole, // Define the permissions granted by the token. You can set it to AdminRole, WriterRole, or ReaderRole
"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
)
);
echo $roomToken;
NETLESSROOM_
in the terminal:php roomtoken.php
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:
<?php
// Import Composer to manage dependencies
require __DIR__ . '/vendor/autoload.php';
use Netless\Token\Generate;
$netlessToken = new Generate;
$roomToken = $netlessToken->roomToken(
"Your AK", // Fill in the AK you get from Agora Console
"Your SK", // Fill in the SK you get from Agora Console
1000 * 60 * 10, // Token validity period in milliseconds. If you set it to 0, the token will never expire
array(
"role" => Generate::ReaderRole, // Define the permissions granted by the token. You can set it to AdminRole, WriterRole, or ReaderRole
"uuid" => "Your Task UUID" // Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task
)
);
echo $sdkToken;
NETLESSTASK_
in the terminal:php tasktoken.php
In the netless-token-master/ruby
folder, you can find:
token.rb
file, which contains the source code for generating tokens.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
:
gem install uuidtools
ruby
folder, create a file named sdktoken.rb
, and copy the following code into it:require './lib/token.rb'
sdktoken = NetlessToken.sdk_token(
"Your AK", # Fill in the AK you get from Agora Console
"Your SK", # Fill in the SK you get from Agora Console
1000 * 60 * 10, # Token validity period in milliseconds. If you set it to 0, the token will never expire
{
:role => NetlessToken::ROLE::ADMIN # Define the permissions granted by the token. You can set it to ADMIN, WRITER, or READER
}
)
puts sdktoken
NETLESSSDK_
in the terminal:ruby sdktoken.rb
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
:
gem install uuidtools
ruby
folder, create a file named roomtoken.rb
, and copy the following code into it:require './lib/token.rb'
roomtoken = NetlessToken.room_token(
"Your AK", # Fill in the AK you get from Agora Console
"Your SK", # Fill in the SK you get from Agora Console
1000 * 60 * 10, # Token validity period in milliseconds. If you set it to 0, the token will never expire
{
:role => NetlessToken::ROLE::ADMIN # Define the permissions granted by the token. You can set it to ADMIN, WRITER, or READER
: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
}
)
puts roomtoken
NETLESSROOM_
in the terminal:ruby roomtoken.rb
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
:
gem install uuidtools
ruby
folder, create a file named tasktoken.rb
, and copy the following code into it:require './lib/token.rb'
tasktoken = NetlessToken.task_token(
"Your AK", # Fill in the AK you get from Agora Console
"netless sk", # Fill in the SK you get from Agora Console
1000 * 60 * 10, # Token validity period in milliseconds. If you set it to 0, the token will never expire
{
:role => NetlessToken::ROLE::ADMIN # Define the permissions granted by the token. You can set it to ADMIN, WRITER, or READER
:uuid => "Your Room UUID" # Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task
}
)
puts tasktoken
NETLESSTASK_
in the terminal:ruby tasktoken.rb
In the netless-token-master/csharp
folder, you can find:
Token.cs
file, which contains the source code for generating tokens.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.
using System;
using Netless;
class Program
{
static void Main(string[] args)
{
string token = NetlessToken.SdkToken(
// Fill in the AK you get from Agora Console
"ak",
// Fill in the SK you get from Agora Console
"sk",
// Set the Token validity period. If you set it to 0, the token will never expire
1000 * 60 * 10,
// Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
new SdkContent(TokenRole.Admin));
Console.WriteLine(token);
}
}
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:
using System;
using Netless;
class Program
{
static void Main(string[] args)
{
string token = NetlessToken.RoomToken(
// Fill in the AK you get from Agora Console
"ak",
// Fill in the SK you get from Agora Console
"sk",
// Set the Token validity period. If you set it to 0, the token will never expire
1000 * 60 * 10,
// Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
// Fill in the Room UUID. You can get it by calling the RESTful API to create a room or get a room list
new RoomContent(TokenRole.Admin, "房间的 UUID")
);
Console.WriteLine(token);
}
}
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:
using System;
using Netless;
class Program
{
static void Main(string[] args)
{
string token = NetlessToken.RoomToken(
// Fill in the AK you get from Agora Console
"ak",
// Fill in the SK you get from Agora Console
"sk",
// Set the Token validity period. If you set it to 0, the token will never expire
1000 * 60 * 10,
// Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
// Fill in the Task UUID. You can get it by calling the RESTful API to start a file-conversion task
new TaskContent(TokenRole.Admin, "Your Task UUID")
);
Console.WriteLine(token);
}
}
NETLESSTASK_
in the terminal.