dflydev/stack-basic-authentication

dev-master / 1.0.x-dev 2014-12-08 22:04 UTC

This package is auto-updated.

Last update: 2024-08-29 03:31:22 UTC


README

A Stack middleware to enable HTTP Basic Authentication following the STACK-2 Authentication conventions.

安装

通过 Composer 作为 dflydev/stack-basic-authentication 安装。

用法

BasicAuthentication中间件接受以下选项

  • authenticator: (必需) 用于确保指定凭证正确的回调函数。
  • realm: 根据 RFC1945 定义的HTTP基本认证领域。
  • firewall: 与 dflydev/stack-firewall 兼容的防火墙配置。
<?php

$authenticator = function ($username, $password) {
    // Given a username and password credentials, ensure that
    // the credentials are correct and return a token that
    // represents the user for this request.
    if ('admin' === $username && 'default' === $password) {
        return 'admin-user-token';
    }
};

$app = new Dflydev\Stack\BasicAuthentication($app, [
    'firewall' => [
        ['path' => '/', 'anonymous' => true],
        ['path' => '/login'],
    ],
    'authenticator' => $authenticator,
    'realm' => 'here there be dragons',
]);

示例

查看 examples/ 目录中此中间件的一些实际使用示例。

许可证

MIT, 查看 LICENSE。

社区

如果您有问题或想提供帮助,请加入我们 irc.freenode.net 上的 #stackphp#dflydev 频道。