Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page

Generate OAuth apps Access Token


Access token can be generated by calling the Access token API endpoint and passing Client ID and Client Secret of an OAuth app.


token Properties

token-properties page anchor
Property nameTypeRequiredDescriptionChild properties
accessTokenstring

Optional

Not PII

Token which carries the necessary information to access a Twilio resource directly.


refreshTokenstring

Optional

Token which carries the information necessary to get a new access token.


idTokenstring

Optional

Token which carries the information necessary of user profile.


tokenTypestring

Optional

Token type


expiresIninteger<int64>

Optional


POST https://oauth.twilio.com/v2/token

Request body parameters

request-body-parameters page anchor
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
grantTypestring

Optional

Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token.


clientIdstring

Optional

A 34 character string that uniquely identifies this OAuth App.


clientSecretstring

Optional

The credential for confidential OAuth App.


codestring

Optional

JWT token related to the authorization code grant type.


redirectUristring

Optional

The redirect uri


audiencestring

Optional

The targeted audience uri


refreshTokenstring

Optional

JWT token related to refresh access token.


scopestring

Optional

The scope of token

Generate Access TokenLink to code sample: Generate Access Token
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 createOauth2Token() {
11
const token = await client.oauth.v2.token.create({
12
clientId: "OQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
13
clientSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
14
grantType: "client_credentials",
15
});
16
17
console.log(token.accessToken);
18
}
19
20
createOauth2Token();

Response

Note about this response
1
{
2
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
3
"refresh_token": "ghjbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
4
"id_token": "eyJhbdGciOiIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
5
"expires_in": 1438315200000,
6
"token_type": "bearer"
7
}

The response contains an access_token property which has to be used to call the Twilio APIs.