TokenAuth
A Plug that provides Bearer authentication by checking whether the request's authorization matches a value.
Installation
{:token_auth, "~> 1.3"}Usage
Plug it in your router or pipeline:
plug(:match)
plug(TokenAuth)
plug(:dispatch)Then in you config set the token:
config :token_auth,
token: "TOKEN",
realm: "Your app",
excluded: ["/public"]If you want to use an environment variable, you can use System.get_env:
config :token_auth,
token: System.get_env("YOURAPP_TOKEN"),
realm: System.get_env("YOURAPP_NAME")Try it out:
curl -X http://localhost:4000/protected -H "Authorization: Bearer TOKEN"