ExTwilio v0.7.0 ExTwilio.WorkerCapability View Source

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.WorkerCapability.new("worker_sid", "workspace_sid")
|> ExTwilio.WorkerCapability.token
"xxxxx.yyyyy.zzzzz"

Link to this section Summary

Functions

Combines generate_claims/1 and encode_and_sign/2

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 policies

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

Sets the Twilio worker sid used to sign the capability token

Sets the Twilio workspace sid used to sign the capability token

Link to this section Types

Link to this type

t() View Source
t() :: %ExTwilio.WorkerCapability{
  account_sid: String.t() | nil,
  auth_token: String.t() | nil,
  policies: list(),
  start_time: non_neg_integer() | nil,
  ttl: non_neg_integer() | nil,
  worker_sid: String.t() | nil,
  workspace_sid: String.t() | nil
}

Link to this section Functions

Link to this function

allow(policies, url, method, query_filters \\ %{}, post_filters \\ %{}) View Source

Link to this function

allow_activity_updates(capability_struct) View Source

Link to this function

allow_reservation_updates(capability_struct) View Source

Link to this function

generate_and_sign(extra_claims \\ %{}, key \\ __default_signer__()) View Source
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
generate_and_sign!(Joken.claims(), Joken.signer_arg()) ::
  Joken.bearer_token() | no_return()

Same as generate_and_sign/2 but raises if error

Link to this function

new(worker_sid, workspace_sid) View Source
new(String.t(), String.t()) :: 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.WorkerCapability.new
Link to this function

starting_at(capability_struct, start_time) View Source
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.WorkerCapability.starting_at(1464096368)
Link to this function

token(worker_capability) View Source
token(t()) :: String.t()

Generates a JWT token based on the requested policies

Example

Generates and signs a token with the provided capabilities

ExTwilio.WorkerCapability.token
Link to this function

verify_and_validate(bearer_token, key \\ __default_signer__(), context \\ %{}) View Source
verify_and_validate(Joken.bearer_token(), Joken.signer_arg(), term()) ::
  {:ok, Joken.claims()} | {:error, Joken.error_reason()}

Combines verify/2 and validate/1

Link to this function

verify_and_validate!(bearer_token, key \\ __default_signer__(), context \\ %{}) View Source
verify_and_validate!(Joken.bearer_token(), Joken.signer_arg(), term()) ::
  Joken.claims() | no_return()

Same as verify_and_validate/2 but raises if error

Link to this function

with_account_sid(capability_struct, account_sid) View Source
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.WorkerCapability.with_account_sid('XXX')
Link to this function

with_auth_token(capability_struct, auth_token) View Source
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.WorkerCapability.with_auth_token('XXX')
Link to this function

with_ttl(capability_struct, ttl) View Source
with_ttl(t(), non_neg_integer()) :: t()

Sets the TTL of the token in seconds.

Example

Sets the TTL to one hour

ExTwilio.WorkerCapability.with_ttl(3600)
Link to this function

with_worker_sid(capability_struct, worker_sid) View Source
with_worker_sid(t(), String.t()) :: t()

Sets the Twilio worker sid used to sign the capability token.

Example

Sets the worker sid to be XXX

ExTwilio.WorkerCapability.with_worker_sid('XXX')
Link to this function

with_workspace_sid(capability_struct, workspace_sid) View Source
with_workspace_sid(t(), String.t()) :: t()

Sets the Twilio workspace sid used to sign the capability token.

Example

Sets the workspace sid to be XXX

ExTwilio.WorkerCapability.with_workspace_sid('XXX')