How to use the twilio.AccessToken function in twilio

To help you get started, we’ve selected a few twilio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TwilioDevEd / api-snippets / rest / access-tokens / ip-messaging-example / ip-messaging-example.2.x.js View on Github external
var serviceSid = 'ISxxxxxxxxxxxxx';
var appName = 'HipFlowSlackDockRC';
var identity = 'user@example.com';
var deviceId = 'someiosdeviceid';
var endpointId = appName + ':' + identity + ':' + deviceId;

// Create a "grant" which enables a client to use IPM as a given user,
// on a given device
var ipmGrant = new IpMessagingGrant({
    serviceSid: serviceSid,
    endpointId: endpointId
});

// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(ipmGrant);
token.identity = identity;

// Serialize the token to a JWT string
console.log(token.toJwt());
github TwilioDevEd / api-snippets / rest / access-tokens / voice-example / voice-example.2.x.js View on Github external
const twilioAccountSid = 'ACxxxxxxxxxx';
const twilioApiKey = 'SKxxxxxxxxxx';
const twilioApiSecret = 'xxxxxxxxxxxx';

// Used specifically for creating Voice tokens
const outgoingApplicationSid = 'APxxxxxxxxxxxxx';
const identity = 'user';

// Create a "grant" which enables a client to use Voice as a given user
const voiceGrant = new VoiceGrant({
  outgoingApplicationSid: outgoingApplicationSid,
});

// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(voiceGrant);
token.identity = identity;

// Serialize the token to a JWT string
console.log(token.toJwt());
github IBM-Cloud / assistant-shop.r / app.js View on Github external
app.get('/ntsToken/:name', function (request, response) {
var AccessToken = require('twilio').AccessToken;

// Substitute your Twilio AccountSid and ApiKey details
var API_KEY_SID = process.ENV.TWILIO_API_KEY;
var API_KEY_SECRET = process.env.TWILIO_API_KEY_SECRET;

// Create an Access Token
var accessToken = new AccessToken(
  twilioCreds.accountSID,
  API_KEY_SID,
  API_KEY_SECRET
);

// Set the Identity of this token
accessToken.identity = request.params.name;

// Grant access to Conversations
var grant = new AccessToken.ConversationsGrant();
grant.configurationProfileSid = process.env.TWILIO_PROFILE_SID;
accessToken.addGrant(grant);

// Serialize the token as a JWT
var jwt = accessToken.toJwt();
console.log(jwt);
github TwilioDevEd / api-snippets / video / users / token-generation-server-rooms / token-generation-server.2.x.js View on Github external
app.get('/token', function(request, response) {
    var identity = randomUsername();
    
    // Create an access token which we will sign and return to the client,
    // containing the grant we just created
    var token = new AccessToken(
        process.env.TWILIO_ACCOUNT_SID,
        process.env.TWILIO_API_KEY,
        process.env.TWILIO_API_SECRET
    );

    //assign the generated identity to the token
    token.identity = identity;
        
    //grant the access token Twilio Video capabilities
    var grant = new VideoGrant();
    grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
    token.addGrant(grant);

    // Serialize the token to a JWT string and include it in a JSON response
    response.send({
        identity: identity,
github crcastle / collaborative-code-conference / src / server / index.js View on Github external
var getToken = function(request, response) {
  log.debug('Generating Twilio token');
  var identity = request.query.identity;

  // Create an access token which we will sign and return to the client,
  // containing the grant we just created
  var token = new AccessToken(
    process.env.TWILIO_ACCOUNT_SID,
    process.env.TWILIO_API_KEY,
    process.env.TWILIO_API_SECRET
  );

  // Assign the generated identity to the token
  token.identity = identity;

  //grant the access token Twilio Video capabilities
  var grant = new ConversationsGrant();
  grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
  token.addGrant(grant);

  // Serialize the token to a JWT string and include it in a JSON response
  response.send({
    identity: identity,
github TwilioDevEd / api-snippets / video / users / token-generation-server / token-generation-server.2.x.js View on Github external
app.get('/token', function(request, response) {
    var identity = randomUsername();
    
    // Create an access token which we will sign and return to the client,
    // containing the grant we just created
    var token = new AccessToken(
        process.env.TWILIO_ACCOUNT_SID,
        process.env.TWILIO_API_KEY,
        process.env.TWILIO_API_SECRET
    );

    //assign the generated identity to the token
    token.identity = identity;
        
    //grant access to Video
    var grant = new VideoGrant();
    grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
    token.addGrant(grant);

    // Serialize the token to a JWT string and include it in a JSON response
    response.send({
        identity: identity,
github crcastle / collaborative-code-conference / index.js View on Github external
var getToken = function(request, response) {
  log.debug('Generating Twilio token');
  var identity = request.query.identity;

  // Create an access token which we will sign and return to the client,
  // containing the grant we just created
  var token = new AccessToken(
    process.env.TWILIO_ACCOUNT_SID,
    process.env.TWILIO_API_KEY,
    process.env.TWILIO_API_SECRET
  );

  // Assign the generated identity to the token
  token.identity = identity;

  //grant the access token Twilio Video capabilities
  var grant = new ConversationsGrant();
  grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
  token.addGrant(grant);

  // Serialize the token to a JWT string and include it in a JSON response
  response.send({
    identity: identity,
github dialogflow / dialogflow-nodejs-client / samples / twilio / ip-messaging / src / twiliobot.js View on Github external
var appName = this.botConfig.apiaiAccessToken;
            var deviceId = "server";

            // Create a unique ID for the client on their current device
            var endpointId = "TwilioChat:" + this.botConfig.botIdentity + ":browser";

            // Create a "grant" which enables a client to use IPM as a given user,
            // on a given device
            var ipmGrant = new IpMessagingGrant({
                serviceSid: this.botConfig.serviceSid,
                endpointId: endpointId
            });

            // Create an access token which we will sign and return to the client,
            // containing the grant we just created
            var token = new AccessToken(
                this.botConfig.accountSid,
                this.botConfig.signingKeySid,
                this.botConfig.signingKeySecret
            );
            token.addGrant(ipmGrant);
            token.identity = this.botConfig.botIdentity;

            resolve(token.toJwt());
        });
    }
github twilio / twilio-video.js / test / lib / token.js View on Github external
function createToken(identity, options) {
  options = Object.assign({}, defaults, options);

  const {
    accountSid,
    apiKeySecret,
    apiKeySid,
    configurationProfileSid,
    ttl
  } = options;

  const accessToken = new AccessToken(
    accountSid,
    apiKeySid,
    apiKeySecret,
    { ttl });

  accessToken.identity = identity;

  let grant = options.grant;
  switch (grant) {
    case 'conversations':
      grant = new AccessToken.ConversationsGrant({
        identity,
        configurationProfileSid
      });
      break;
    case 'video':
github TwilioDevEd / hangouts-clone-react / server.js View on Github external
client.verifyIdToken(body.tokenId, process.env.GOOGLE_CLIENT_ID, (e, login) => {
      const payload = login.getPayload();
      const userId = payload.sub;
      if (userId === body.googleId) {
        const token = new AccessToken(
          process.env.TWILIO_ACCOUNT_SID,
          process.env.TWILIO_API_KEY,
          process.env.TWILIO_API_SECRET
        );

        token.identity = body.googleId;

        const grant = new VideoGrant();
        grant.configurationProfileSid = process.env.TWILIO_CONFIGURATION_SID;
        token.addGrant(grant);
        
        response.send({
          identity: body.googleId,
          token: token.toJwt(),
        });
      } else {