Created
February 9, 2016 09:28
-
-
Save willrax/9c6ab0ce663c6df17e9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Plugger.Authenticate do | |
def init(opts), do: opts | |
def call(conn, opts) do | |
conn | |
|> get_auth_headers | |
|> authenticate(opts[:token]) | |
end | |
def get_auth_headers(conn) do | |
{conn, Plug.Conn.get_req_header(conn, "authorization")} | |
end | |
def authenticate({conn, [token]}, token) do | |
conn | |
end | |
def authenticate({conn, _}, token) do | |
conn | |
|> Plug.Conn.send_resp(401, "Not Authorised") | |
|> Plug.Conn.halt | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment