twilio.util

class twilio.util.RequestValidator(token)
compute_signature(uri, params, utf=False)

Compute the signature for a given request

Parameters:
  • uri – full URI that Twilio requested on your server
  • params – post vars that Twilio sent with the request
  • utf – whether return should be bytestring or unicode (python3)
Returns:

The computed signature

validate(uri, params, signature)

Validate a request from Twilio

Parameters:
  • uri – full URI that Twilio requested on your server
  • params – post vars that Twilio sent with the request
  • signature – expexcted signature in HTTP X-Twilio-Signature header
Returns:

True if the request passes validation, False if not

class twilio.util.TwilioCapability(account_sid, auth_token)

A token to control permissions with Twilio Client

Parameters:
  • account_sid (str) – the account sid to which this token is granted access
  • auth_token (str) – the secret key used to sign the token. Note, this auth token is not visible to the user of the token.
Returns:

A new TwilioCapability with zero permissions

allow_client_incoming(client_name)

If the user of this token should be allowed to accept incoming connections then configure the TwilioCapability through this method and specify the client name.

Parameters:client_name (str) – Client name to accept calls from
allow_client_outgoing(application_sid, **kwargs)

Allow the user of this token to make outgoing connections.

Keyword arguments are passed to the application.

Parameters:application_sid (str) – Application to contact
generate(expires=3600)

Generate a valid JWT token with an expiration date.

Parameters:expires (int) – The token lifetime, in seconds. Defaults to 1 hour (3600)