ExTwilio v0.2.1 ExTwilio.Capability

Capability tokens are used to sign communications from devices to Twilio. You create a token on your server, specify what capabilities you would like your device to have, then pass the token to your client to use. The tokens generated are JSON Web Tokens (JWT).

Example

ExTwilio.Capability.new
|> ExTwilio.Capability.allow_client_incoming("tommy")
|> ExTwilio.Capability.allow_client_outgoing("APabe7650f654fc34655fc81ae71caa3ff")
|> ExTwilio.Capability.token
"xxxxx.yyyyy.zzzzz"

Summary

Functions

Gives the device a client name allowing incoming connections to the client identified by the provided client_name

Gives the device an application sid so that Twilio can determine the voice URL to use to handle any outgoing connection

Initialises a new capability specification with a TTL of one hour, and the accound sid and auth token taken from the configuration

Sets the time at which the TTL begins in seconds since epoch

Generates a JWT token based on the requested capabilities that can be provided to the Twilio client. Supports clients with multiple capabilties

Sets the Twilio account sid used to issue the token

Sets the Twilio account auth token used to sign the capability token

Sets the TTL of the token in seconds

Types

t :: %ExTwilio.Capability{account_sid: String.t | nil, auth_token: String.t | nil, incoming_client_names: list, outgoing_client_app_sid: String.t | nil, start_time: non_neg_integer | nil, ttl: non_neg_integer | nil}

Functions

allow_client_incoming(client_name)

Specs

allow_client_incoming(String.t) :: t

Gives the device a client name allowing incoming connections to the client identified by the provided client_name.

Example

A device with this token will be identified as tommy

ExTwilio.Capability.allow_client_incoming("tommy")
allow_client_incoming(capability, client_name)

Specs

allow_client_incoming(t, String.t) :: t
allow_client_outgoing(app_sid)

Specs

allow_client_outgoing(String.t) :: t

Gives the device an application sid so that Twilio can determine the voice URL to use to handle any outgoing connection.

Example

Outgoing connections will use the Twilio application with the SID: APabe7650f654fc34655fc81ae71caa3ff

ExTwilio.Capability.allow_client_outgoing("APabe7650f654fc34655fc81ae71caa3ff")
allow_client_outgoing(capability, app_sid)

Specs

allow_client_outgoing(t, String.t) :: t
new()

Specs

new :: t

Initialises a new capability specification with a TTL of one hour, and the accound sid and auth token taken from the configuration.

Example

ExTwilio.Capability.new
starting_at(capability, start_time)

Specs

starting_at(t, non_neg_integer) :: t

Sets the time at which the TTL begins in seconds since epoch.

Example

Sets the TTL to begin on 24th May, 2016

ExTwilio.Capability.starting_at(1464096368)
token(capability)

Specs

token(t) :: String.t

Generates a JWT token based on the requested capabilities that can be provided to the Twilio client. Supports clients with multiple capabilties.

Example

Generates and signs a token with the provided capabilities

ExTwilio.Capability.token
with_account_sid(capability, account_sid)

Specs

with_account_sid(t, String.t) :: t

Sets the Twilio account sid used to issue the token.

Example

Sets the account sid to be XXX

ExTwilio.Capability.with_account_sid('XXX')
with_auth_token(capability, auth_token)

Specs

with_auth_token(t, String.t) :: t

Sets the Twilio account auth token used to sign the capability token.

Example

Sets the auth token to be XXX

ExTwilio.Capability.with_auth_token('XXX')
with_ttl(capability, ttl)

Specs

with_ttl(t, non_neg_integer) :: t

Sets the TTL of the token in seconds.

Example

Sets the TTL to one hour

ExTwilio.Capability.with_ttl(3600)