View Source ExTwilio.Capability (ExTwilio v0.10.0)

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).

Examples

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.

Combines generate_claims/1 and encode_and_sign/2

Initialises a new capability specification with a TTL of one hour, and the account 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

@type outgoing_client_app() :: {String.t(), map()}
@type t() :: %ExTwilio.Capability{
  account_sid: String.t() | nil,
  auth_token: String.t() | nil,
  incoming_client_names: list(),
  outgoing_client_app: outgoing_client_app() | nil,
  start_time: non_neg_integer() | nil,
  ttl: non_neg_integer() | nil
}

Functions

Link to this function

allow_client_incoming(client_name)

View Source
@spec allow_client_incoming(String.t()) :: t()

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

Examples

A device with this token will be identified as tommy

ExTwilio.Capability.allow_client_incoming("tommy")
Link to this function

allow_client_incoming(capability_struct, client_name)

View Source
@spec allow_client_incoming(t(), String.t()) :: t()
Link to this function

allow_client_outgoing(app_sid)

View Source
@spec 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.

Examples

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

ExTwilio.Capability.allow_client_outgoing("APabe7650f654fc34655fc81ae71caa3ff")
Link to this function

allow_client_outgoing(app_sid, app_params)

View Source
@spec allow_client_outgoing(String.t(), map()) :: t()
@spec allow_client_outgoing(t(), String.t()) :: t()
Link to this function

allow_client_outgoing(capability_struct, app_sid, app_params)

View Source
@spec allow_client_outgoing(t(), String.t(), map()) :: t()
Link to this function

generate_and_sign(extra_claims \\ %{}, key \\ __default_signer__())

View Source
@spec generate_and_sign(Joken.claims(), Joken.signer_arg()) ::
  {:ok, Joken.bearer_token(), Joken.claims()} | {:error, Joken.error_reason()}

Combines generate_claims/1 and encode_and_sign/2

Link to this function

generate_and_sign!(extra_claims \\ %{}, key \\ __default_signer__())

View Source
@spec generate_and_sign!(Joken.claims(), Joken.signer_arg()) :: Joken.bearer_token()

Same as generate_and_sign/2 but raises if error

@spec new() :: t()

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

Examples

ExTwilio.Capability.new
Link to this function

starting_at(capability_struct, start_time)

View Source
@spec starting_at(t(), non_neg_integer()) :: t()

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

Examples

Sets the TTL to begin on 24th May, 2016

ExTwilio.Capability.starting_at(1464096368)
Link to this function

token(capability_struct)

View Source
@spec 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.

Examples

Generates and signs a token with the provided capabilities

ExTwilio.Capability.token
Link to this function

verify_and_validate(bearer_token, key \\ __default_signer__(), context \\ %{})

View Source
@spec verify_and_validate(Joken.bearer_token(), Joken.signer_arg(), term()) ::
  {:ok, Joken.claims()} | {:error, Joken.error_reason()}

Combines verify/2 and validate/2

Link to this function

verify_and_validate!(bearer_token, key \\ __default_signer__(), context \\ %{})

View Source
@spec verify_and_validate!(Joken.bearer_token(), Joken.signer_arg(), term()) ::
  Joken.claims()

Same as verify_and_validate/2 but raises if error

Link to this function

with_account_sid(capability_struct, account_sid)

View Source
@spec with_account_sid(t(), String.t()) :: t()

Sets the Twilio account sid used to issue the token.

Examples

Sets the account sid to be XXX

ExTwilio.Capability.with_account_sid('XXX')
Link to this function

with_auth_token(capability_struct, auth_token)

View Source
@spec with_auth_token(t(), String.t()) :: t()

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

Examples

Sets the auth token to be XXX

ExTwilio.Capability.with_auth_token('XXX')
Link to this function

with_ttl(capability_struct, ttl)

View Source
@spec with_ttl(t(), non_neg_integer()) :: t()

Sets the TTL of the token in seconds.

Examples

Sets the TTL to one hour

ExTwilio.Capability.with_ttl(3600)