Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

nicer example in README

  • Loading branch information...
commit 82b4ec16775ce638519b1d8730dfd072ac7f4ca5 1 parent 216f047
@martinrehfeld martinrehfeld authored
Showing with 28 additions and 21 deletions.
  1. +28 −21 README.md
View
49 README.md
@@ -1,25 +1,15 @@
# Basic Authentication Middleware for Elli
-Use it like this:
-
- PasswordCheck =
- fun (User, Password) ->
- case {User, Password} of
- {undefined, undefined} -> unauthorized;
- {<<"admin">>, <<"secret">>} -> ok;
- {User, Password} -> forbidden
- end
- end,
-
- AuthFun =
- fun (Req, User, Password) ->
- case elli_request:path(Req) of
- [<<"protected">>] -> PasswordCheck(User, Password);
- _ -> ok
- end
- end,
-
- BasicauthConfig = [{auth_fun, AuthFun},
+Use it together with the [Elli webserver](https://github.com/knutin/elli)
+like this:
+
+```erlang
+-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
],
@@ -30,4 +20,21 @@ Use it like this:
]}
],
- elli:start_link([{callback, elli_middleware}, {callback_args, Config}]).
+ 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.
+```
Please sign in to comment.
Something went wrong with that request. Please try again.