Teac.Plug.CacheBodyReader (teac v1.0.0)

Copy Markdown View Source

A Plug.Parsers body reader that caches the raw request body in conn.assigns.

Use this with Plug.Parsers in your Phoenix Endpoint so that Teac.Plug.EventSub can verify the Twitch HMAC signature after the body has already been parsed.

Endpoint configuration

plug Plug.Parsers,
  parsers: [:urlencoded, :multipart, :json],
  pass: ["*/*"],
  body_reader: {Teac.Plug.CacheBodyReader, :read_body, []},
  json_decoder: JSON

The raw body is stored under conn.assigns[:raw_body] as a binary string.

Summary

Functions

read_body(conn, opts)