Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

typesend/mailgun_webhook_auth

A Plug for validating Mailgun Webhook requests in Elixir applications

typesend/mailgun_webhook_auth.json
{
"createdAt": "2016-02-14T22:04:01Z",
"defaultBranch": "master",
"description": "A Plug for validating Mailgun Webhook requests in Elixir applications",
"fullName": "typesend/mailgun_webhook_auth",
"homepage": "",
"language": "Elixir",
"name": "mailgun_webhook_auth",
"pushedAt": "2016-02-15T00:26:10Z",
"stargazersCount": 2,
"topics": [],
"updatedAt": "2017-08-15T13:01:11Z",
"url": "https://github.com/typesend/mailgun_webhook_auth"
}

This is a Plug module for validating Mailgun Webhook requests in Elixir applications.

A 403 Unauthorized Webhook Request response is returned for all invalid requests. All other requests pass through unmodified.

Add mailgun_webhook_auth to the deps function in your project’s mix.exs file:

defp deps do
[{:mailgun_webhook_auth, "~> 1.0"}]
end

Then run mix do deps.get, deps.compile inside your project’s directory.

Recommended usage is within a pipeline, but it may be used within your Phoenix controllers; anywhere a Plug can be used.

It expects your private mailgun API token String to be passed at initialization.

pipeline :webhooks do
plug MailgunWebhookAuth,
api_token: Application.get_env(:your_application, :mailgun_key)
end
scope "/webhooks", YourApplication do
pipe_through :webhooks
post "/received", WebhookController, :received
post "/delivered", WebhookController, :delivered
post "/dropped", WebhookController, :dropped
post "/bounced", WebhookController, :bounced
post "/complaints", WebhookController, :complaints
post "/unsubscribes", WebhookController, :unsubscribes
post "/clicks", WebhookController, :clicks
post "/opens", WebhookController, :opens
end
config :your_application, mailgun_key: "key-BLAHBLAHBLAH"

See the Mailgun Routes documentation for more information.

MailgunWebhookAuth uses the same Apache 2 license as Plug and the Elixir programming language. See the license file for more information.