Skip to contentSkip to navigationSkip to topbar
On this page

REST API: Network Traversal Service Tokens


Network Traversal Service Tokens are ephemeral credentials that let you access TURN resources from WebRTC and VoIP clients. They are a secure way to create communication sessions with web browsers or mobile apps without exposing credentials in a client-side environment. All tokens have a limited lifetime to protect you from abuse. The lifetime is configurable up to 24 hours (which is also the default value) but you should make it as short as possible for your application.


Token List Resource

list page anchor

Resource URI

list-uri page anchor
1
/2010-04-01/Accounts/{AccountSid}/Tokens
2

A Token instance resource has the following properties

PropertyDescription
UsernameThe temporary username that uniquely identifies a Token.
PasswordThe temporary password that the username will use when authenticating with Twilio.
TtlThe duration in seconds for which the username and password are valid, the default value is 86,400 (24 hours)
AccountSidThe unique id of the Account that created this Token.
IceServersAn array representing the ephemeral credentials and the STUN and TURN server URIs.
DateCreatedThe date that this resource was created, given in RFC 2822(link takes you to an external page) format.
DateUpdatedThe date that this resource was last updated, given in RFC 2822(link takes you to an external page) format.

Not Supported

You can create a new Token resource by POSTing to the Tokens list resource. Since the purpose of tokens is to provide short-lived credentials, usernames and passwords are always auto-generated and not intended to be stored long term.

Optional Parameters

post-parameters-optional page anchor

You may POST the following parameters:

ParameterDescription
TtlThe duration in seconds for which the generated credentials are valid, the default value is 86400 (24 hours).
Create a Token ResourceLink to code sample: Create a Token Resource
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createToken() {
11
const token = await client.tokens.create();
12
13
console.log(token.accountSid);
14
}
15
16
createToken();

Output

1
{
2
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
3
"ice_servers": [
4
{
5
"urls": "stun:global.stun.twilio.com:3478"
6
},
7
{
8
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
9
"credential": "tE2DajzSJwnsSbc123",
10
"urls": "turn:global.turn.twilio.com:3478?transport=udp"
11
},
12
{
13
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
14
"credential": "tE2DajzSJwnsSbc123",
15
"urls": "turn:global.turn.twilio.com:3478?transport=tcp"
16
},
17
{
18
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
19
"credential": "tE2DajzSJwnsSbc123",
20
"urls": "turn:global.turn.twilio.com:443?transport=tcp"
21
}
22
],
23
"date_updated": "Fri, 01 May 2020 01:42:57 +0000",
24
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
25
"ttl": "86400",
26
"date_created": "Fri, 01 May 2020 01:42:57 +0000",
27
"password": "tE2DajzSJwnsSbc123"
28
}
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createToken() {
11
const token = await client.tokens.create({ ttl: 3600 });
12
13
console.log(token.accountSid);
14
}
15
16
createToken();

Output

1
{
2
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
3
"ice_servers": [
4
{
5
"urls": "stun:global.stun.twilio.com:3478"
6
},
7
{
8
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
9
"credential": "tE2DajzSJwnsSbc123",
10
"urls": "turn:global.turn.twilio.com:3478?transport=udp"
11
},
12
{
13
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
14
"credential": "tE2DajzSJwnsSbc123",
15
"urls": "turn:global.turn.twilio.com:3478?transport=tcp"
16
},
17
{
18
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
19
"credential": "tE2DajzSJwnsSbc123",
20
"urls": "turn:global.turn.twilio.com:443?transport=tcp"
21
}
22
],
23
"date_updated": "Fri, 01 May 2020 01:42:57 +0000",
24
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
25
"ttl": 3600,
26
"date_created": "Fri, 01 May 2020 01:42:57 +0000",
27
"password": "tE2DajzSJwnsSbc123"
28
}

Not Supported.

Not Supported.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.