| 1 |
HTTP Basic Authentication |
| 2 |
========================= |
| 3 |
|
| 4 |
|image0| |
| 5 |
|
| 6 |
Presentation |
| 7 |
------------ |
| 8 |
|
| 9 |
|
| 10 |
.. attention:: |
| 11 |
|
| 12 |
For now, this feature is only supported by Apache |
| 13 |
handler. |
| 14 |
|
| 15 |
Extract from the `Wikipedia |
| 16 |
article <http://en.wikipedia.org/wiki/Basic_access_authentication>`__: |
| 17 |
|
| 18 |
In the context of an HTTP transaction, the basic access authentication |
| 19 |
is a method designed to allow a web browser, or other client program, to |
| 20 |
provide credentials – in the form of a user name and password – when |
| 21 |
making a request. |
| 22 |
|
| 23 |
Before transmission, the username and password are encoded as a sequence |
| 24 |
of base-64 characters. For example, the user name Aladdin and password |
| 25 |
open sesame would be combined as Aladdin:open sesame – which is |
| 26 |
equivalent to QWxhZGRpbjpvcGVuIHNlc2FtZQ== when encoded in Base64. |
| 27 |
Little effort is required to translate the encoded string back into the |
| 28 |
user name and password, and many popular security tools will decode the |
| 29 |
strings "on the fly". |
| 30 |
|
| 31 |
So HTTP Basic Authentication is managed through an HTTP header |
| 32 |
(``Authorization``), that can be forged by LL::NG, with this |
| 33 |
precautions: |
| 34 |
|
| 35 |
- Data should not contains accents or special characters, as HTTP |
| 36 |
protocol only allow ASCII values in header (but depending on the HTTP |
| 37 |
server, you can use ISO encoded values) |
| 38 |
- You need to forward the password, which can be the user main password |
| 39 |
(if :doc:`password is stored in session<../passwordstore>`, or any |
| 40 |
user attribute (if you keep secondary passwords in users database). |
| 41 |
|
| 42 |
Configuration |
| 43 |
------------- |
| 44 |
|
| 45 |
The Basic Authentication relies on a specific HTTP header, as described |
| 46 |
above. So you have just to declare this header for the virtual host in |
| 47 |
Manager. |
| 48 |
|
| 49 |
For example, to forward login (``$uid``) and password (``$_password`` if |
| 50 |
:doc:`password is stored in session<../passwordstore>`): |
| 51 |
|
| 52 |
:: |
| 53 |
|
| 54 |
Authorization => "Basic ".encode_base64("$uid:$_password", "") |
| 55 |
|
| 56 |
LL::NG provides a special function named |
| 57 |
:doc:`basic<../extendedfunctions>` to build this header. |
| 58 |
|
| 59 |
So the above example can also be written like this: |
| 60 |
|
| 61 |
:: |
| 62 |
|
| 63 |
Authorization => basic($uid,$_password) |
| 64 |
|
| 65 |
|
| 66 |
.. tip:: |
| 67 |
|
| 68 |
The ``basic`` function will also force conversion from UTF-8 |
| 69 |
to ISO-8859-1, which should be accepted by most of HTTP servers. |
| 70 |
|
| 71 |
.. |image0| image:: /applications/http_logo.png |
| 72 |
:class: align-center |
| 73 |
|