rossriley/stack-basic-authentication

HTTP基本认证堆栈中间件

dev-master / 1.0.x-dev 2014-03-24 15:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:40:01 UTC


README

A Stack 中间件,用于启用遵循 HTTP基本认证 的约定 STACK-2 认证

分支信息

此包从以下原始作品分支而来: https://packagist.org.cn/packages/dflydev/stack-basic-authentication

这是一个使其与框架无关的尝试,因为原始版本依赖于 Silex / Pimple

安装

通过 Composer 安装,作为 rossriley/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 频道。