Twilio. AccessToken
(twilio v0.2.0)
Copy Markdown
Access tokens for Twilio's client SDKs: the Voice SDK in a browser or app, Video, Conversations (Chat), Sync.
Your server makes a short-lived token for a user, and the client SDK uses it to talk to Twilio directly:
token =
Twilio.AccessToken.generate(
identity: "alice",
grants: [voice: [outgoing_application_sid: "AP...", incoming_allow: true]]
)Tokens are signed with an API key
(SK... and its secret), not your auth token. The key, its secret and your
account SID come from the options, else from your config, else from the
environment:
config :twilio,
account_sid: "AC...",
api_key_sid: "SK...",
api_key_secret: "..."
# or TWILIO_ACCOUNT_SID, TWILIO_API_KEY and TWILIO_API_SECRETThe token is the same JWT Twilio's official SDKs make: HS256, a
twilio-fpa;v=1 content type, and the grants below.
Summary
Functions
A signed access token, as a string.
Functions
A signed access token, as a string.
Options:
:identity: who the token is for (required for Voice, Chat and Sync):grants: what the token allows, a keyword list:voice: [incoming_allow: true, outgoing_application_sid: "AP...", outgoing_application_params: %{...}, push_credential_sid: "CR...", endpoint_id: "..."]video: [room: "..."]chat: [service_sid: "IS...", endpoint_id: "...", deployment_role_sid: "...", push_credential_sid: "..."](Conversations uses this grant too)sync: [service_sid: "IS...", endpoint_id: "..."]task_router: [workspace_sid: "WS...", worker_sid: "WK...", role: "..."]playback: %{...}, the grant Twilio Live's API returned
:ttl: seconds the token is valid (default 3600; Twilio allows up to 24 hours):valid_until: a Unix time when it expires, instead of:ttl:nbf: a Unix time before which it isn't valid (default: now;falseto leave it out):region: the Twilio region, such as"ie1":account_sid,:api_key_sid,:api_key_secret: see the module docs:now: the current Unix time (for tests)