xabbuh / oauth1-authentication
为 HTTPlug 库提供的 OAuth1 认证
v1.0.0
2017-01-01 11:30 UTC
Requires
- php: ^5.5 || ^7.0
- api-clients/psr7-oauth1: ^2.0 || ^1.0
- php-http/message: ^1.0
Requires (Dev)
- phpspec/phpspec: ~2.3
README
使用 OAuth1 对 PSR-7 请求进行签名,当与 HTTPlug 客户端一起使用时。
安装
使用 Composer 安装 OAuth1 集成
$ composer require xabbuh/oauth1-authentication:^1.0
使用
-
使用您的消费者密钥和密钥配置请求签名器
use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerKey; use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerSecret; use ApiClients\Tools\Psr7\Oauth1\RequestSigning\RequestSigner; $requestSigner = new RequestSigner( new ConsumerKey('consumer_key'), new ConsumerSecret('consumer_secret') );
您还可以可选地指定要使用的哈希算法。更多关于此的信息请参阅api-clients/psr7-oauth1 文档。
-
设置 OAuth1 认证,传递配置的请求签名器以及您的访问令牌和令牌密钥
// ... use ApiClients\Tools\Psr7\Oauth1\Definition\AccessToken; use ApiClients\Tools\Psr7\Oauth1\Definition\TokenSecret; use Xabbuh\Http\Authentication\OAuth1; // ... $oauth = new OAuth1( $requestSigner, new AccessToken('access_token'), new TokenSecret('token_secret') );
-
使用认证插件配置认证
// ... use Http\Discovery\HttpClientDiscovery; use Http\Client\Common\PluginClient; use Http\Client\Common\Plugin\AuthenticationPlugin; // ... $authenticationPlugin = new AuthenticationPlugin($oauth); $pluginClient = new PluginClient( HttpClientDiscovery::find(), [$authenticationPlugin] );