Skip to content
This repository


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

Basic Authentication Middleware for Elli

Use it together with the Elli webserver like this:

-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

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