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.
Property nameTypeRequiredDescriptionChild properties
Token which carries the necessary information to access a Twilio resource directly.
Token which carries the information necessary to get a new access token.
POST https://oauth.twilio.com/v2/token
Encoding type:
application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token.
The scope of token
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createOauth2Token() {11const token = await client.oauth.v2.token.create({12clientId: "OQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",13clientSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",14grantType: "client_credentials",15});1617console.log(token.accessToken);18}1920createOauth2Token();
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.