PlugBasicAuth
A plug for protecting routers with HTTP Basic Auth.
It expects a :username
and :password
to be passed as binaries at initialization.
The user will be prompted for a username and password upon accessing any of the routes using this plug.
If the username and password are correct, the user will be able to access the page.
If the username and password are incorrect, the user will be prompted to enter them again.
Example
defmodule TopSecret do
import Plug.Conn
use Plug.Router
plug PlugBasicAuth, username: "Snorky", password: "Capone"
plug :match
plug :dispatch
get '/speakeasy' do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "Welcome to the party.")
end
end
Summary↑
call(conn, server_creds) |
init(opts) |