StandardWebhooks (standard_webhooks v0.1.1)

Copy Markdown View Source

Documentation for Standard Webhooks

Summary

Functions

Calculate the response to an endpoint verification challenge given a challenge and secret

Sign a Standard Webhook given an id, timestamp, payload and secret

Verify a Standard Webhook given a payload, Plug.Conn and secret

Verify the response to an endpoint verification challenge given a challenge, response and secret

Functions

endpoint_verification_response(challenge, secret)

@spec endpoint_verification_response(challenge :: String.t(), secret :: binary()) ::
  String.t()

Calculate the response to an endpoint verification challenge given a challenge and secret

Takes the value of the webhook-challenge header and returns the value for the webhook-challenge-response header.

sign(id, timestamp, payload, secret)

@spec sign(
  id :: String.t(),
  timestamp :: integer(),
  payload :: binary() | String.t(),
  secret :: binary()
) :: String.t()

Sign a Standard Webhook given an id, timestamp, payload and secret

The payload can be bytes (a binary) or a string (a UTF-8 binary). It's signed byte for byte, so it must be the exact body that will be sent.

validate_timestamp(timestamp)

verify(payload, conn, secret)

@spec verify(binary() | String.t(), Plug.Conn.t(), binary()) :: boolean()

Verify a Standard Webhook given a payload, Plug.Conn and secret

The payload must be the raw request body, exactly as received, either as bytes (a binary) or as a string (a UTF-8 binary). It's verified byte for byte, so don't pass a re-encoded version of the parsed body: even a minor difference in the serialization (e.g. whitespace or key order) will cause verification to fail.

verify_endpoint_verification_response(challenge, header, secret)

@spec verify_endpoint_verification_response(
  challenge :: String.t(),
  header :: String.t(),
  secret :: binary()
) :: boolean()

Verify the response to an endpoint verification challenge given a challenge, response and secret

Takes the challenge that was sent and the value of the webhook-challenge-response header.