greenhollowtech / ght-api-authenticator-bundle
GHT API Authenticator Bundle
2.0.3
2016-05-19 08:33 UTC
Requires
- php: >=5.4
- greenhollowtech/ght-api-authenticator: ~2.0
- symfony/config: ~3.0
- symfony/dependency-injection: ~3.0
- symfony/http-foundation: ~3.0
- symfony/http-kernel: ~3.0
- symfony/security: ~3.0
Requires (Dev)
README
此包将GHT API Authenticator作为服务提供给Symfony。
安装
获取Composer包
使用Composer安装,运行composer require greenhollowtech/ght-api-authenticator-bundle
。对于Symfony 2,请确保指定版本~1.0
。
将GHTApiAuthenticatorBundle添加到您的Symfony应用程序中
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new GHT\ApiAuthenticatorBundle\GHTApiAuthenticatorBundle(),
// ...
);
}
使用方法
设置您的防火墙以使用API认证器。
# app/config/security.yml
security:
...
firewalls:
api:
stateless: true
simple_preauth:
authenticator: ght_api_authenticator
将apiKey
和apiSecret
属性添加到您的用户实体中,以及相关的获取器和设置器。
如果您已经建立了属性,并希望使用现有数据,只需配置API认证器使用这些属性而不是默认值
# app/config/config.yml
ght_api_authenticator:
user_entity:
api_key_property: myKeyPropertyName
api_secret_property: mySecretPropertyName
自定义用户提供者
如果您的应用程序有其他方式加载当前用户,您可以通过定义自己的服务将其提供给API认证器。您的自定义用户提供者作为构造函数的第三个参数传递。
# src/AcmeBundle/Resources/config/services.yml
services:
...
acme_api_user_authenticator:
class: GHT\ApiAuthenticatorBundle\Security\ApiUserAuthenticator
arguments:
- %ght_api_authenticator.user_entity.api_key_property%
- %ght_api_authenticator.user_entity.api_secret_property%
- "@acme_custom_user_provider"
然后在您的防火墙中设置认证器以使用此新服务代替。