View Source ExTwilio.JWT.AccessToken (ExTwilio v0.10.0)

A Twilio JWT access token, as described in the Twilio docs.

https://www.twilio.com/docs/iam/access-tokens

Summary

Types

@type t() :: %ExTwilio.JWT.AccessToken{
  account_sid: String.t(),
  api_key: String.t(),
  api_secret: String.t(),
  expires_in: integer(),
  grants: [ExTwilio.JWT.Grant.t()],
  identity: String.t(),
  token_identifier: term()
}

Functions

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(attrs :: Keyword.t()) :: t()

Creates a new JWT access token.

Examples

AccessToken.new(
  account_sid: "account_sid",
  api_key: "api_key",
  api_secret: "secret",
  identity: "user@email.com",
  expires_in: 86_400,
  grants: [AccessToken.ChatGrant.new(service_sid: "sid")]
)
@spec to_jwt!(t()) :: String.t() | no_return()

Converts an access token into a string JWT.

Will raise errors if the token does not have all the required fields.

Examples

token =
  AccessToken.new(
    account_sid: "account_sid",
    api_key: "api_key",
    api_secret: "secret",
    identity: "user@email.com",
    expires_in: 86_400,
    grants: [AccessToken.ChatGrant.new(service_sid: "sid")]
  )

AccessToken.to_jwt!(token)
# => "eyJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIiwidHlwIjoiSldUIn0.eyJleHAiOjE1MjM5MTIxODgsImdyYW50cyI6eyJjaGF0Ijp7ImVuZHBvaW50X2lkIjpudWxsLCJzZXJ2aWNlX3NpZCI6InNpZCJ9LCJpZGVudGl0eSI6InVzZXJAZW1haWwuY29tIn0sImlhdCI6MTUyMzkwNDk4OCwibmJmIjoxNTIzOTA0OTg3fQ.M_5dsj1VWBrIZKvcIdygSpmiMsrZdkplYYNjxEhBHk0"
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