ExTwilioWebhook.Plug (ex_twilio_webhook v0.0.2)

A module plug that verifies Twilio webhook signatures and halts the request if the signature is invalid.

This plug relies on parsed params, so it must be placed in your Phoenix pipeline after Plug.Parsers.

Link to this section Summary

Functions

Checks whether a request matches the given path pattern and passes it through if it doesn't.

Parses the plug's configuration options

Does the actual webhook validation.

Link to this section Functions

Link to this function

call(conn, settings)

Checks whether a request matches the given path pattern and passes it through if it doesn't.

Parses the plug's configuration options:

  • at: the request path at which the plug will validate webhook signatures. When given a string, it will only match if the request_path is equal to the pattern. When given a regular expression, it will match if the regular expression matches the request_path.

  • secret: Twilio secret. The secret can be provided as a string, an {m, f, a} tuple, or an anonymous function of arity 0 or 1. When given a 1-arity function, the function will be called with the value of the AccountSid of each request. This is useful if your application needs to process webhooks from multiple Twilo accounts. When given an {m, f, a} tuple, the tuple will be called at runtime for each request.

  • public_host: The public URL of your application with scheme, e. g.: https://myapp.com. Can be provided as string or {m, f, a} tuple. When given a tuple, the tuple will be called at runtime for each request.

This function will raise if called with invalid arguments.

Link to this function

normalize_request_url(public_host, conn)

Link to this function

path_matched?(path, regex)

Link to this function

validate_webhook(conn, settings)

Does the actual webhook validation.