Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

Android
iOS
Web

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.

Prerequisites

Ensure that you have enabled Interactive Whiteboard for your Agora Console project.

JavaScript

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.

Generate an SDK Token

Refer to the following steps to generate an SDK Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Node/JavaScript folder and run the following command to install Node.js dependencies:


_1
npm install

  1. Create a file named sdktoken.js and copy the following code into it:

_11
const { sdkToken, TokenPrefix } = require("./index");
_11
// Generate a SDK Token
_11
const 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
{
_11
role: 0 // Define the permissions granted by the token. You can set it to 0 (Admin), 1 (Writer), or 2 (Reader)
_11
}
_11
);
_11
console.log(netlessSDKToken)

  1. Run the following command, after which you should see a token prefixed with NETLESSSDK_ in the terminal:

_1
node sdktoken.js

Generate a Room Token

Refer to the following steps to generate a Room Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Node/JavaScript folder and run the following command to install Node.js dependencies:


_1
npm install

  1. Create a file named roomtoken.js and copy the following code into it:

_12
const { roomToken, TokenPrefix } = require("./index");
_12
// Generate a Room token
_12
const 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
{
_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
_12
}
_12
);
_12
console.log(netlessRoomToken)

  1. Run the following command, after which you should see a token prefixed with NETLESSROOM_ in the terminal:

_1
node roomtoken.js

Generate a Task Token

Refer to the following steps to generate a Task Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Node/JavaScript folder and run the following command to install Node.js dependencies:


_1
npm install

  1. Create a file named tasktoken.js, and copy the following code into it:

_12
const { taskToken, TokenPrefix } = require("./index");
_12
// Generate a Task Token
_12
const 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
{
_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
_12
}
_12
);
_12
console.log(netlessTaskToken)

  1. Run the following command, after which you should see a token prefixed with NETLESSTASK_ in the terminal:

_1
node tasktoken.js

TypeScript

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.

Generate an SDK Token

Refer to the following steps to generate an SDK Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Node/TypeScript folder and run the following command to install TypeScript:


_1
npm install -g typescript

  1. Create a file named sdktoken.ts and copy the following code into it:

_10
import { sdkToken, TokenPrefix } from "./src/index";
_10
const 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
{
_10
role: TokenRole.Admin // Define the permissions granted by the token. You can set it to TokenRole.Admin, TokenRole.Writer, or TokenRole.Reader
_10
}
_10
);
_10
console.log(netlessSDKToken)

  1. Run the following command to generate the corresponding sdktoken.js file:

_1
tsc sdktoken.ts

  1. Run the following command, after which you should see a token prefixed with NETLESSSDK_ in the terminal:

_1
node sdktoken.js

Generate a Room Token

Refer to the following steps to generate a Room Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Node/TypeScript folder and run the following command to install TypeScript:


_1
npm install -g typescript

  1. Create a file named roomtoken.ts and copy the following code into it:

_11
import { roomToken, TokenPrefix } from "./src/index";
_11
const 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
{
_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
_11
}
_11
);
_11
console.log(netlessRoomToken)

  1. Run the following command to generate the corresponding roomtoken.js file:

_1
tsc roomtoken.ts

  1. Run the following command, after which you should see a token prefixed with NETLESSROOM_ in the terminal:

_1
node roomtoken.js

Generate a Task Token

Refer to the following steps to generate a Task Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Node/TypeScript folder and run the following command to install TypeScript:


_1
npm install -g typescript

  1. Create a file named tasktoken.ts and copy the following code into it:

_11
import { taskToken, TokenPrefix } from "./src/index";
_11
const 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
{
_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
_11
}
_11
);
_11
console.log(netlessTaskToken)

  1. Run the following command to generate the corresponding tasktoken.js file:

_1
tsc tasktoken.ts

  1. Run the following command, after which you should see a token prefixed with NETLESSTASK_ in the terminal:

_1
node tasktoken.js

Java

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.

Generate an SDK Token

Refer to the following steps to generate an SDK Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Java folder and add the following code to the Token.java file:


_13
public 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
_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
map);
_13
_13
System.out.println(sdkToken);
_13
}

  1. Go to the directory of the Token.java file and run the following command:

_1
javac Token.java

  1. Run the following command, after which you should see a token prefixed with NETLESSSDK_ in the terminal:

_1
java Token

Generate a Room Token

Refer to the following steps to generate a Room Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Java folder and add the following code to the Token.java file:


_15
public 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
_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
map);
_15
_15
System.out.println(roomToken);
_15
}

  1. Go to the directory of the Token.java file and run the following command:

_1
javac Token.java

  1. Run the following command, after which you should see a token prefixed with NETLESSROOM_ in the terminal:

_1
java Token

Generate a Task Token

Refer to the following steps to generate a Task Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/Java folder and add the following code to the Token.java file:


_15
public 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
_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
map);
_15
_15
System.out.println(taskToken);
_15
}

  1. Go to the directory of the Token.java file and run the following command:

_1
javac Token.java

  1. Run the following command, after which you should see a token prefixed with NETLESSTASK_ in the terminal:

_1
java Token

Golang

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.

Generate an SDK Token

Refer to the following steps to generate an SDK Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Create a file named sdktoken.go and copy the following code into it:


_18
package main
_18
import (
_18
"fmt"
_18
"../golang" // Replace ../golang with the path to the netless-token folder in your local directory
_18
)
_18
func main() {
_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
}
_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
&c,
_18
)
_18
fmt.Println(netlessSDKToken)
_18
}

  1. 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:

_1
go sdktoken.go

Generate a Room Token

Refer to the following steps to generate a Room Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Create a file named roomtoken.go and copy the following code into it:


_20
package main
_20
import (
_20
"fmt"
_20
"../golang" // Replace ../golang with the path to the netless-token folder in your local directory
_20
)
_20
func main() {
_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
}
_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
&c,
_20
)
_20
fmt.Println(netlessRoomToken)
_20
}

  1. 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:

_1
go roomtoken.go

Generate a Task Token

Refer to the following steps to generate a Task Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Create a file named tasktoken.go and copy the following code into it:


_20
package main
_20
import (
_20
"fmt"
_20
"../golang" // Replace ../golang with the path to the netless-token folder in your local directory
_20
)
_20
func main() {
_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
Uuid: "Task UUID",
_20
}
_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
&c,
_20
)
_20
fmt.Println(netlessTaskToken)
_20
}

  1. 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:

_1
go tasktoken.go

PHP

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.

Generate an SDK Token

Refer to the following steps to generate an SDK Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/php folder, create a file named sdktoken.php, and copy the following code into it:


_14
<?php
_14
// Import Composer to manage dependencies
_14
require __DIR__ . '/vendor/autoload.php';
_14
use 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
array(
_14
"role" => Generate::AdminRole, // Define the permissions granted by the token. You can set it to AdminRole, WriterRole, or ReaderRole
_14
)
_14
);
_14
echo $sdkToken;

  1. Run the following command, after which you should see a token prefixed with NETLESSSDK_ in the terminal:

_1
php sdktoken.php

Generate a Room Token

Refer to the following steps to generate a Room Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/php folder, create a file named roomtoken.php, and copy the following code into it:


_15
<?php
_15
// Import Composer to manage dependencies
_15
require __DIR__ . '/vendor/autoload.php';
_15
use 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
array(
_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
_15
)
_15
);
_15
echo $roomToken;

  1. Run the following command, after which you should see a token prefixed with NETLESSROOM_ in the terminal:

_1
php roomtoken.php

Generate a Task Token

Refer to the following steps to generate a Task Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/php folder, create a file named tasktoken.php, and copy the following code into it:


_15
<?php
_15
// Import Composer to manage dependencies
_15
require __DIR__ . '/vendor/autoload.php';
_15
use 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
array(
_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
_15
)
_15
);
_15
echo $sdkToken;

  1. Run the following command, after which you should see a token prefixed with NETLESSTASK_ in the terminal:

_1
php tasktoken.php

Ruby

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.

Generate an SDK Token

Refer to the following steps to generate an SDK Token:

  1. Download the netless-token repository, or clone it to a local directory.

  2. Go to the netless-token-master/ruby folder and run the following command to install uuidtools:


_1
gem install uuidtools

  1. In the ruby folder, create a file named sdktoken.rb and copy the following code into it:

_10
require './lib/token.rb'
_10
sdktoken = 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
{
_10
:role => NetlessToken::ROLE::ADMIN # Define the permissions granted by the token. You can set it to ADMIN, WRITER, or READER
_10
}
_10
)
_10
puts sdktoken

  1. Run the following command, after which you should see a token prefixed with NETLESSSDK_ in the terminal:

_1
ruby sdktoken.rb

Generate a Room Token

Refer to the following steps to generate a Room Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/ruby folder and run the following command to install uuidtools:


_1
gem install uuidtools

  1. In the ruby folder, create a file named roomtoken.rb and copy the following code into it:

_11
require './lib/token.rb'
_11
roomtoken = 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
{
_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
_11
}
_11
)
_11
puts roomtoken

  1. Run the following command, after which you should see a token prefixed with NETLESSROOM_ in the terminal:

_1
ruby roomtoken.rb

Generate a Task Token

Refer to the following steps to generate a Task Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/ruby folder, and run the following command to install uuidtools:


_1
gem install uuidtools

  1. In the ruby folder, create a file named tasktoken.rb and copy the following code into it:

_11
require './lib/token.rb'
_11
tasktoken = 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
{
_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
_11
}
_11
)
_11
puts tasktoken

  1. Run the following command, after which you should see a token prefixed with NETLESSTASK_ in the terminal:

_1
ruby tasktoken.rb

C Sharp

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.

Generate an SDK Token

Refer to the following steps to generate an SDK Token:

  1. Download the netless-token repository, or clone it to a local directory.

  2. Go to the netless-token-master/csharp folder and open the csharp.sln file in Visual Studio.

  3. Fill in your AK, SK, token validity period, and token role in the Program.cs file.


_18
using System;
_18
using Netless;
_18
class Program
_18
{
_18
static void Main(string[] args)
_18
{
_18
string token = NetlessToken.SdkToken(
_18
// Fill in the AK you get from Agora Console
_18
"ak",
_18
// Fill in the SK you get from Agora Console
_18
"sk",
_18
// Set the Token validity period. If you set it to 0, the token will never expire
_18
1000 * 60 * 10,
_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);
_18
}
_18
}

  1. Run the project in Visual Studio. You should see a token prefixed with NETLESSSDK_ in the terminal.

Generate a Room Token

Refer to the following steps to generate a Room Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/csharp folder and open the csharp.sln file in Visual Studio.

  3. Delete the code in the Program.cs file and copy the following sample code into it:


_20
using System;
_20
using Netless;
_20
class Program
_20
{
_20
static void Main(string[] args)
_20
{
_20
string token = NetlessToken.RoomToken(
_20
// Fill in the AK you get from Agora Console
_20
"ak",
_20
// Fill in the SK you get from Agora Console
_20
"sk",
_20
// Set the Token validity period. If you set it to 0, the token will never expire
_20
1000 * 60 * 10,
_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
);
_20
Console.WriteLine(token);
_20
}
_20
}

  1. Run the project in Visual Studio. You should see a token prefixed with NETLESSROOM_ in the terminal.

Generate a Task Token

Refer to the following steps to generate a Task Token:

  1. Download the netless-token repository or clone it to a local directory.

  2. Go to the netless-token-master/csharp folder and open the csharp.sln file in Visual Studio.

  3. Delete the code in the Program.cs file and copy the following sample code into it:


_20
using System;
_20
using Netless;
_20
class Program
_20
{
_20
static void Main(string[] args)
_20
{
_20
string token = NetlessToken.RoomToken(
_20
// Fill in the AK you get from Agora Console
_20
"ak",
_20
// Fill in the SK you get from Agora Console
_20
"sk",
_20
// Set the Token validity period. If you set it to 0, the token will never expire
_20
1000 * 60 * 10,
_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
);
_20
Console.WriteLine(token);
_20
}
_20
}

  1. Run the project in Visual Studio. You should see a token prefixed with NETLESSTASK_ in the terminal.
vundefined