Skip to content

Access Token error due to library changes in newer versions of twilio-node #561

@danohn

Description

@danohn

Description

When running the Quickstart and requesting an Access Token from e.g. https://quickstart-1234-dev.twil.io/access-token, an error is returned with the following message:

{
  "message": "identity is required to be specified in options",
  "name": "Error",
  "stack": "Error: identity is required to be specified in options\n    at new AccessToken (/var/task/node_modules/twilio/lib/jwt/AccessToken.js:28:19)\n    at exports.handler (/var/task/handlers/ZNf10e7cbc86844358c2a38dee2f1bd9a4.js:18:17)\n    at exports.handler (/var/task/node_modules/runtime-handler/index.js:339:10)\n    at exports.handler (/var/task/runtime-handler.js:17:17)\n    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
}

Steps to Reproduce

  1. Clone the repo
  2. Copy the .env.example file and update the .env file as needed
  3. Run the twilio serverless:deploy command
  4. Attempt to retrieve an Access Token from e.g. https://quickstart-1234-dev.twil.io/access-token

Expected Behavior

The function should mint an Access Token

Actual Behavior

The function returns the error:

{
  "message": "identity is required to be specified in options",
  "name": "Error",
  "stack": "Error: identity is required to be specified in options\n    at new AccessToken (/var/task/node_modules/twilio/lib/jwt/AccessToken.js:28:19)\n    at exports.handler (/var/task/handlers/ZNf10e7cbc86844358c2a38dee2f1bd9a4.js:18:17)\n    at exports.handler (/var/task/node_modules/runtime-handler/index.js:339:10)\n    at exports.handler (/var/task/runtime-handler.js:17:17)\n    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
}

Reproduces How Often

100%

Fix

As per This Stack Overflow answer, with version 4 and above of the Node.js client (the current default for serverless functions is 5.0.3), you now need to supply an identity property in the AccessToken config. For example:

  const token = new AccessToken(
    twilioAccountSid,
    twilioApiKey,
    twilioApiSecret,
    { identity }
  );
  token.addGrant(voiceGrant);
  // token.identity = identity;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions