ExTwilio.Capability (ExTwilio v0.8.2) 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.Capability.new
|> ExTwilio.Capability.allow_client_incoming("tommy")
|> ExTwilio.Capability.allow_client_outgoing("APabe7650f654fc34655fc81ae71caa3ff")
|> ExTwilio.Capability.token
"xxxxx.yyyyy.zzzzz"
Link to this section 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
Same as generate_and_sign/2
but raises if error
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.
Combines verify/2
and validate/1
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.
Link to this section Types
Specs
Specs
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 }
Link to this section Functions
Specs
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")
Specs
Specs
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")
Specs
Specs
generate_and_sign(extra_claims \\ %{}, key \\ __default_signer__())
View SourceSpecs
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 SourceSpecs
generate_and_sign!(Joken.claims(), Joken.signer_arg()) :: Joken.bearer_token() | no_return()
Same as generate_and_sign/2
but raises if error
Specs
new() :: t()
Initialises a new capability specification with a TTL of one hour, and the account sid and auth token taken from the configuration.
Example
ExTwilio.Capability.new
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)
Specs
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
verify_and_validate(bearer_token, key \\ __default_signer__(), context \\ %{})
View SourceSpecs
verify_and_validate(Joken.bearer_token(), Joken.signer_arg(), term()) :: {:ok, Joken.claims()} | {:error, Joken.error_reason()}
Combines verify/2
and validate/1
verify_and_validate!(bearer_token, key \\ __default_signer__(), context \\ %{})
View SourceSpecs
verify_and_validate!(Joken.bearer_token(), Joken.signer_arg(), term()) :: Joken.claims() | no_return()
Same as verify_and_validate/2
but raises if error
Specs
Sets the Twilio account sid used to issue the token.
Example
Sets the account sid to be XXX
ExTwilio.Capability.with_account_sid('XXX')
Specs
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')
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)