fabricekabongo / auth0-api-authentication-bundle
与Auth0集成,将API身份验证引入Symfony
v0.4.2
2017-03-24 20:32 UTC
Requires
- auth0/auth0-php: ^5.0
- symfony/framework-bundle: *
- symfony/http-kernel: ^2.7
- symfony/security: ^2.7
This package is auto-updated.
Last update: 2024-09-19 21:39:56 UTC
README
徽章
步骤 1:下载Bundle
打开命令行,进入您的项目目录,然后执行以下命令以下载此Bundle的最新稳定版本
$ composer require fabricekabongo/auth0symfonyapiauthenticator
此命令要求您已全局安装Composer,具体请参阅Composer文档中的安装章节。
步骤 2:启用Bundle
然后,通过将其添加到项目app/AppKernel.php文件中注册的Bundle列表来启用此Bundle
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new FabriceKabongo\Auth0\APIAuthenticationBundle\APIAuthenticationBundle(), ); // ... } // ... }
然后,在app/config/security.yml中将身份验证器和提供者设置为以下值
# app/config/security.yml security: # ... firewalls: secured_area: pattern: ^/youbaseurl stateless: true simple_preauth: authenticator: fabricekabongo.auth0.services.apikeyuserauthenticator provider: api_key_user_provider anonymous: true providers: api_key_user_provider: id: fabricekabongo.auth0.services.apikeyuserprovider access_control: - { path: ^/youbaseurl, roles: ROLE_USER }
# app/config/config.yml fabrice_kabongo_auth0_api_authentication_bundle: valid_audiences: - 'https://your.service.indentifier' authorized_iss: - 'https://youraccount.auth0.com'
请参阅Auth0 API
步骤 3:为您的API编写功能测试
创建一个功能测试,并扩展FabriceKabongo\Auth0\APIAuthenticationBundle\Test\AuthenticatedWebTestCase。在测试用例中创建一个客户端,并将其与您希望用户拥有的角色一起传递给setUpClient方法
public function testMyOwnTestCase() { $client = $this->setUpClient( static::createClient(), ['ROLE_READ_PROFIL', 'ROLE_EDIT_PAYMENTINFO'] ); // do your http calls and do your test as usual }
步骤 4:帮助我使它更好、更简单。请:)
待办事项:编写单元测试(我将如何模拟JWS验证器) 待办事项:为其他版本的Symfony创建新分支(如果工作方式不同) 待办事项:引入酷炫的新功能。
我喜欢这个项目,并将继续为其工作。请同样做。