|
| 1 | +HTTP Basic Authentication Stack Middleware |
| 2 | +========================================== |
| 3 | + |
| 4 | +A [Stack][0] middleware to enable [HTTP Basic Authentication][1] following the |
| 5 | +[STACK-2 Authentication][2] conventions. |
| 6 | + |
| 7 | + |
| 8 | +Installation |
| 9 | +------------ |
| 10 | + |
| 11 | +Through [Composer][3] as [dflydev/stack-basic-authentication][4]. |
| 12 | + |
| 13 | + |
| 14 | +Usage |
| 15 | +----- |
| 16 | + |
| 17 | +The BasuciAuthentication middleware accepts the following options: |
| 18 | + |
| 19 | + * **authenticator**: *(required)* A callback used to ensure that the specified |
| 20 | + credentials are correct. |
| 21 | + * **realm**: The HTTP Basic Authentication realm as defined by [RFC1945][5]. |
| 22 | + * **firewall**: A firewall configuration compatible with |
| 23 | + [dflydev/stack-firewall][6]. |
| 24 | + |
| 25 | +```php |
| 26 | +<?php |
| 27 | + |
| 28 | +$authenticator = function ($username, $password) { |
| 29 | + // Given a username and password credentials, ensure that |
| 30 | + // the credentials are correct and return a token that |
| 31 | + // represents the user for this request. |
| 32 | + if ('admin' === $username && 'default' === $password) { |
| 33 | + return 'admin-user-token'; |
| 34 | + } |
| 35 | +}; |
| 36 | + |
| 37 | +$app = new Dflydev\Stack\BasicAuthentication($app, [ |
| 38 | + 'firewall' => [ |
| 39 | + ['path' => '/', 'anonymous' => true], |
| 40 | + ['path' => '/login'], |
| 41 | + ], |
| 42 | + 'authenticator' => $authenticator, |
| 43 | + 'realm' => 'here there be dragons', |
| 44 | +]); |
| 45 | +``` |
| 46 | + |
| 47 | +Examples |
| 48 | +-------- |
| 49 | + |
| 50 | +See the `examples/` directory for some live examples of this middleware in |
| 51 | +action. |
| 52 | + |
| 53 | + |
| 54 | +License |
| 55 | +------- |
| 56 | + |
| 57 | +MIT, see LICENSE. |
| 58 | + |
| 59 | + |
| 60 | +Community |
| 61 | +--------- |
| 62 | + |
| 63 | +If you have questions or want to help out, join us in the **#stackphp** or **#dflydev** channels on **irc.freenode.net**. |
| 64 | + |
| 65 | + |
| 66 | +[0]: http://stackphp.com/ |
| 67 | +[1]: http://en.wikipedia.org/wiki/Basic_access_authentication |
| 68 | +[2]: http://stackphp.com/specs/STACK-2/ |
| 69 | +[3]: http://getcomposer.org |
| 70 | +[4]: https://packagist.org/packages/dflydev/stack-basic-authentication |
| 71 | +[5]: http://tools.ietf.org/html/rfc1945#section-11 |
| 72 | +[6]: https://packagist.org/packages/dflydev/stack-firewall |
0 commit comments