api-skeletons / zf-oauth2-client
zfcampus/zf-oauth2的OAuth2客户端
Requires
- php: >=5.5
- zendframework/zend-http: ~2.5
- zendframework/zend-i18n: ~2.5
- zendframework/zend-mvc: ~2.5
- zendframework/zend-servicemanager: ~2.5
- zendframework/zend-session: ~2.5
- zendframework/zend-uri: ~2.5
Requires (Dev)
- mockery/mockery: ^0.9
- phpunit/phpunit: ^4
- satooshi/php-coveralls: ^0.6.1
- squizlabs/php_codesniffer: ^2
- zendframework/zend-config: ~2.5
- zendframework/zend-log: ~2.5
- zendframework/zend-modulemanager: ~2.5
- zendframework/zend-serializer: ~2.5
- zendframework/zend-test: ~2.5
This package is auto-updated.
Last update: 2024-09-11 13:57:00 UTC
README
当你编写一个包含zfcampus/zf-oauth2的应用程序时,此模块被编写以轻松且干净地连接到该zf-oauth2实现。
安装
此模块的安装使用composer。有关composer文档,请参阅getcomposer.org。
composer require api-skeletons/zf-oauth2-client ^1.0
将此模块添加到应用程序的配置
'modules' => array( ... 'ZF\OAuth2\Client', ),
此模块通过模块提供服务管理器配置,但你也可以直接通过注入自己的Zend\Http\Client
和配置来使用ZF\OAuth2\Client\OAuth2Client
类。
配置
将config/zf-oauth2-client.global.php.dist
复制到config/autoload/zf-oauth2-client-global.php
并编辑。你可以配置多个zf-oauth2授权代码提供者配置文件。login_redirect_route是你的认证路由。
'zf-oauth2-client' => array( 'profiles' => array( 'default' => array( 'login_redirect_route' => 'zfcuser', 'client_id' => 'client', 'secret' => 'password', 'endpoint' => 'http://localhost:8081/oauth', 'refresh_endpoint' => 'http://localhost:8081/oauth', 'scope' = 'list,of,scopes', ), /* 'other provider' => array( ... */ ), ),
zf-oauth2服务器配置
zf-oauth2-client期望服务器在每次使用刷新令牌获取新访问令牌时返回一个新的刷新令牌。要在zf-oauth2上设置此标志,请使用
return array( 'zf-oauth2' => array( 'options' => array( 'always_issue_new_refresh_token' => true, ), ), );
使用
提供了一个控制器,用于将用户发送到授权代码流程,并在用户返回时验证代码。验证后,会话将有一个有效的access_token。
要将用户发送到授权代码流程,请直接将他们导向zf-oauth2-client路由。
// Controller $this->plugin('redirect') ->toRoute('zf-oauth2-client', array('profile' => 'default')); // View $this->url('zf-oauth2-client', array('profile' => 'default'));
当用户从流程返回时,他们将被重定向到login_redirect_route。此路由应获取授权的http客户端,并使用它根据从OAuth2服务器返回的API调用结果中的配置文件对用户进行认证。
命令行工具
为了使JWT更容易测试,包括了一些命令行工具。
oauth2:jwt:generate
生成一个JWT,并将其发送到OAuth2的grant_type
为urn:ietf:params:oauth:grant-type:jwt-bearer
。