Skip to contentSkip to navigationSkip to topbar
Rate 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

_10
/2010-04-01/Accounts/{AccountSid}/Tokens

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).
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.tokens.create().then(token => console.log(token.username));

Output

_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"ice_servers": [
_28
{
_28
"urls": "stun:global.stun.twilio.com:3478"
_28
},
_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"credential": "tE2DajzSJwnsSbc123",
_28
"urls": "turn:global.turn.twilio.com:3478?transport=udp"
_28
},
_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"credential": "tE2DajzSJwnsSbc123",
_28
"urls": "turn:global.turn.twilio.com:3478?transport=tcp"
_28
},
_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"credential": "tE2DajzSJwnsSbc123",
_28
"urls": "turn:global.turn.twilio.com:443?transport=tcp"
_28
}
_28
],
_28
"date_updated": "Fri, 01 May 2020 01:42:57 +0000",
_28
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_28
"ttl": "86400",
_28
"date_created": "Fri, 01 May 2020 01:42:57 +0000",
_28
"password": "tE2DajzSJwnsSbc123"
_28
}

Create Token Resource during 1 hour

create-token-resource-during-1-hour page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.tokens.create({ttl: 3600}).then(token => console.log(token.username));

Output

_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"ice_servers": [
_28
{
_28
"urls": "stun:global.stun.twilio.com:3478"
_28
},
_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"credential": "tE2DajzSJwnsSbc123",
_28
"urls": "turn:global.turn.twilio.com:3478?transport=udp"
_28
},
_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"credential": "tE2DajzSJwnsSbc123",
_28
"urls": "turn:global.turn.twilio.com:3478?transport=tcp"
_28
},
_28
{
_28
"username": "dc2d2894d5a9023620c467b0e71cfa6a35457e6679785ed6ae9856fe5bdfa269",
_28
"credential": "tE2DajzSJwnsSbc123",
_28
"urls": "turn:global.turn.twilio.com:443?transport=tcp"
_28
}
_28
],
_28
"date_updated": "Fri, 01 May 2020 01:42:57 +0000",
_28
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_28
"ttl": 3600,
_28
"date_created": "Fri, 01 May 2020 01:42:57 +0000",
_28
"password": "tE2DajzSJwnsSbc123"
_28
}

Not Supported.

Not Supported.


Rate this Page: