softonic/guzzle-oauth2-middleware

Guzzle 中间件,具有 OAuth2 集成

2.1.1 2024-06-21 10:47 UTC

This package is auto-updated.

Last update: 2024-09-12 08:30:56 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads Average time to resolve an issue Percentage of issues still open

此包为 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