View Source Plaid.Webhooks (elixir_plaid v1.2.1)

Verify webhooks from plaid and construct the raw body into structs

Link to this section Summary

Functions

Verify that a webhook is actually from plaid, constructing the raw body into an event struct.

Link to this section Functions

Link to this function

verify_and_construct(jwt, raw_body, config)

View Source

Specs

verify_and_construct(String.t(), String.t(), Plaid.config()) ::
  {:ok, struct()}
  | {:error, :invalid_algorithm | :invalid_body | :unknown | Plaid.Error.t()}

Verify that a webhook is actually from plaid, constructing the raw body into an event struct.

Adheres to the guidelines outlined in this guide from plaid to verify webhooks.

🏗 Only missing piece from the plaid guidelines is public key caching.

examples

Examples

Webhooks.verify_and_construct(
  "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
  ~s({"webhook_type": "ITEM", "webhook_code": "ERROR"}),
  client_id: "abc",
  secret: "123"
)
{:ok, %Webhooks.ItemError{}}