helthe/security-api

Helthe API 安全组件

1.0.0 2014-02-21 05:29 UTC

This package is auto-updated.

Last update: 2024-08-29 03:11:58 UTC


README

Helthe API 安全是一个库,用于使用 Symfony 安全组件进行 API 密钥认证。

安装

使用 Composer

手动安装

在您的 composer.json 中添加以下内容

{
    "require": {
        // ...
        "helthe/security-api": "~1.0"
    }
}

使用命令行

$ composer require 'helthe/security-api=~1.0'

使用方法

认证提供者

提供了一个实现 AuthenticationProviderInterface 的 API 认证提供者,支持 PreAuthenticatedToken。一旦认证成功,用户将通过 ApiKeyAuthenticatedToken 进行认证,它是 PreAuthenticatedToken 的扩展,其中不会删除 API 密钥。

用户提供者

该库提供自己的 UserProviderInterface,必须由提供给 ApiKeyAuthenticationProvider 的用户提供者实现。

示例

use Helthe\Component\Security\Api\Authentication\Provider\ApiKeyAuthenticationProvider;
use Symfony\Component\Security\Core\User\UserChecker;

// Helthe\Component\Security\Api\User\UserProviderInterface
$userProvider = new InMemoryUserProvider(
    array(
        'admin' => array(
            'api_key' => 'foo',
        ),
    )
);

// for some extra checks: is account enabled, locked, expired, etc.?
$userChecker = new UserChecker();

$provider = new ApiKeyAuthenticationProvider(
    $userProvider,
    $userChecker,
    'your_api',
);

$provider->authenticate($unauthenticatedToken);

防火墙

提供了两个扩展自 AbstractPreAuthenticatedListener 的防火墙监听器。 HttpHeaderListener 检查 Request 头部中的 API 密钥,而 QueryStringListener 检查 Request 查询字符串。

错误

对于错误或功能请求,请 创建一个问题