warxcell / guzzle-oauth2-middleware
Guzzle 中间件,支持 OAuth2 集成
2.0.0
2020-12-16 09:55 UTC
Requires
- php: >=5.6
- league/oauth2-client: ^2.2
- psr/cache: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.4
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2024-09-16 20:09:50 UTC
README
此包为 guzzle 提供中间件,用于在 OAuth2 令牌到期时透明地处理令牌协商和续订。它接受 PHP League 的 OAuth 2.0 客户端。
安装
要安装,请使用 composer
composer require softonic/guzzle-oauth2-middleware
使用方法
<?php $options = [ 'clientId' => 'myclient', 'clientSecret' => 'mysecret' ]; // Any provider extending League\OAuth2\Client\Provider\AbstractProvider will do $provider = new Softonic\OAuth2\Client\Provider\Softonic($options); // Send OAuth2 parameters and use token_options for any other parameters your OAuth2 provider needs $config = ['grant_type' => 'client_credentials', 'scope' => 'myscope', 'token_options' => ['audience' => 'test_audience']]; // Any implementation of PSR-6 Cache will do $cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter(); $client = \Softonic\OAuth2\Guzzle\Middleware\ClientBuilder::build( $provider, $config, $cache, ['base_uri' => 'https://foo.bar/'] ); $response = $client->request('POST', 'qux);
测试
softonic/guzzle-oauth2-middleware
拥有 PHPUnit 测试套件和代码风格合规性测试套件,使用 PHP CS Fixer。
要从项目目录运行测试,请运行以下命令。
$ docker-compose run test
要使用 PsySH 交互式运行
$ docker-compose run psysh
许可证
Apache 2.0 许可证。请参阅 LICENSE 了解更多信息。