View Source ExTwilio.WorkerCapability (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.WorkerCapability.new("worker_sid", "workspace_sid")
|> ExTwilio.WorkerCapability.token
"xxxxx.yyyyy.zzzzz"
Summary
Functions
Combines generate_claims/1
and encode_and_sign/2
Same as generate_and_sign/2
but raises if error
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.
Combines verify/2
and validate/2
Same as verify_and_validate/2
but raises if error
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.
Types
@type 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 }
Functions
allow(policies, url, method, query_filters \\ %{}, post_filters \\ %{})
View Sourcegenerate_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
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
Initialises a new capability specification with a TTL of one hour, and the accound sid and auth token taken from the configuration.
Examples
ExTwilio.WorkerCapability.new
@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.WorkerCapability.starting_at(1464096368)
Generates a JWT token based on the requested policies.
Examples
Generates and signs a token with the provided capabilities:
ExTwilio.WorkerCapability.token
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
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
Sets the Twilio account sid used to issue the token.
Examples
Sets the account sid to be XXX:
ExTwilio.WorkerCapability.with_account_sid('XXX')
Sets the Twilio account auth token used to sign the capability token.
Examples
Sets the auth token to be XXX:
ExTwilio.WorkerCapability.with_auth_token('XXX')
@spec with_ttl(t(), non_neg_integer()) :: t()
Sets the TTL of the token in seconds.
Examples
Sets the TTL to one hour:
ExTwilio.WorkerCapability.with_ttl(3600)
Sets the Twilio worker sid used to sign the capability token.
Examples
Sets the worker sid to be XXX:
ExTwilio.WorkerCapability.with_worker_sid('XXX')
Sets the Twilio workspace sid used to sign the capability token.
Examples
Sets the workspace sid to be XXX:
ExTwilio.WorkerCapability.with_workspace_sid('XXX')