Skip to content

martinrehfeld/elli_basicauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Basic Authentication middleware for the Elli webserver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages