gamez/mite-api-authentication

此包已被弃用且不再维护。作者建议使用gamez/mite包代替。

支持访问mite API的认证中间件

1.0 2018-09-05 13:36 UTC

This package is auto-updated.

Last update: 2022-02-01 13:14:33 UTC


README

支持访问mite API的认证中间件

此包已不再维护。请使用https://github.com/jeromegamez/mite-php代替。

安装

composer require gamez/mite-api-authentication

使用

Guzzle

http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html

use Gamez\Mite\MiteAuthenticationMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

$stack = HandlerStack::create();
$stack->push(new MiteAuthenticationMiddleware('accountname', 'apikey'));

$client = new Client(['handler' => $stack]);

HTTPlug

http://docs.php-http.org/en/latest/plugins/authentication.html

use Gamez\Mite\MiteAuthentication;
use Http\Discovery\HttpClientDiscovery;
use Http\Message\Authentication\BasicAuth;
use Http\Client\Common\PluginClient;
use Http\Client\Common\Plugin\AuthenticationPlugin;

$authentication = new MiteAuthentication('accountname', 'apikey');
$authenticationPlugin = new AuthenticationPlugin($authentication);

$client = new PluginClient(
    HttpClientDiscovery::find(),
    [$authenticationPlugin]
);

自定义

use Gamez\Mite\MiteRequestAuthenticator;

$authenticator = new MiteRequestAuthenticator('accountname', 'apikey');
$request = ...; // an implementation of Psr\Http\Message\RequestInterface

$authenticatedRequest = $authenticator->authenticate($request);