Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Basic Authentication middleware for the Elli webserver

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

Basic Authentication Middleware for Elli

Use it together with the Elli webserver like this:

-module(my_elli_stuff).
-export([start_link/0, auth_fun/3]).

start_link() ->
    BasicauthConfig = [
                       {auth_fun, fun my_elli_stuff:auth_fun/3},
                       {auth_realm, <<"Admin Area">>} % optional
                      ],

    Config = [
              {mods, [
                      {elli_basicauth, BasicauthConfig},
                      {elli_example_callback, []}
                     ]}
             ],

    elli:start_link([{callback, elli_middleware},
                     {callback_args, Config}]).


auth_fun(Req, User, Password) ->
    case elli_request:path(Req) of
        [<<"protected">>] -> password_check(User, Password);
        _                 -> ok
    end.


password_check(User, Password) ->
    case {User, Password} of
        {undefined, undefined}      -> unauthorized;
        {<<"admin">>, <<"secret">>} -> ok;
        {User, Password}            -> forbidden
    end.
Something went wrong with that request. Please try again.