Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lexmag/blaguth
Basic Access Authentication in Plug applications
https://github.com/lexmag/blaguth
elixir
Last synced: 8 days ago
JSON representation
Basic Access Authentication in Plug applications
- Host: GitHub
- URL: https://github.com/lexmag/blaguth
- Owner: lexmag
- License: isc
- Created: 2014-11-04T12:16:10.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-05-17T11:05:21.000Z (over 6 years ago)
- Last Synced: 2024-10-13T19:06:02.668Z (22 days ago)
- Topics: elixir
- Language: Elixir
- Homepage:
- Size: 14.6 KB
- Stars: 20
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Basic Access Authentication in Plug applications. (Framework Components)
- fucking-awesome-elixir - blaguth - Basic Access Authentication in Plug applications. (Framework Components)
- awesome-elixir - blaguth - Basic Access Authentication in Plug applications. (Framework Components)
README
# Blaguth
[![Build Status](https://travis-ci.org/lexmag/blaguth.svg)](https://travis-ci.org/lexmag/blaguth)
[![Hex Version](https://img.shields.io/hexpm/v/blaguth.svg "Hex Version")](https://hex.pm/packages/blaguth)[Basic Access Authentication](http://tools.ietf.org/html/rfc2617) in Plug applications.
## Installation
Add Blaguth as a dependency to your `mix.exs` file:
```elixir
defp deps do
[{:blaguth, "~> 1.2.0"}]
end
```After you are done, run `mix deps.get` in your shell to fetch the dependencies.
## Usage
Add Blaguth on top of a Plug Stack as follows:
```elixir
defmodule CavePlug do
import Plug.Conn
use Plug.Builderplug Blaguth, realm: "Secret",
credentials: {"Ali Baba", "Open Sesame"}plug :index
def index(conn, _opts) do
send_resp(conn, 200, "Hello Ali Baba")
end
end
```If you need more precise control over authentication process:
```elixir
defmodule AdvancedPlug do
import Plug.Conn
use Plug.Routerplug Blaguth
plug :match
plug :dispatchget "/" do
send_resp(conn, 200, "Everyone can see me!")
endget "/secret" do
if authenticated?(conn.assigns) do
send_resp(conn, 200, "I'm only accessible if you know the password")
else
Blaguth.halt_with_login(conn, "Secret")
end
enddefp authenticated?(%{credentials: {user, pass}}) do
User.authenticate(user, pass)
end
end
```## License
This software is licensed under [the ISC license](LICENSE).