qbnk/guzzle5-oauth2-subscriber
Composer 安装命令:
composer require qbnk/guzzle5-oauth2-subscriber
包简介
OAuth2 authentication and reauthorization for Guzzle 5.x - forked and based on nmrkt/guzzle5-oauth2-subscriber
README 文档
README
Forked from NMRKT/guzzle5-oauth2-subscriber and fixed a few bugs
The NMRKT implementation seems abandoned as they have not responded to any of the merge requests. We then decided to publish our fixes.
Provides an OAuth2 subscriber for Guzzle 5.x.
Attribution
This plugin is based on the Guzzle 3.x OAuth2 plugin by Bojan Zivanovic and Damien Tournoud from the CommerceGuys guzzle-oauth2-plugin repository.
I originally forked that project, but moved to a new repo since most of the code has changed and I needed to reset the versions to < 1.0.
Features
- Acquires access tokens via one of the supported grant types (code, client credentials, user credentials, refresh token). Or you can set an access token yourself.
- Supports refresh tokens (stores them and uses them to get new access tokens).
- Handles token expiration (acquires new tokens and retries failed requests).
- Allows storage and lookup of access tokens via callbacks
Usage
This plugin extends Guzzle, transparently adding authentication to outgoing requests and optionally attempting reauthorization if the access token is no longer valid.
There are several grant types available like PasswordCredentials, ClientCredentials and AuthorizationCode.
Access Token Method
If you already have an access token, you can use that to authenticate to a service, but beware that access tokens are meant to expire, and the process of obtaining a new access token is included in this library as well (for example, by using the PasswordCredentials method).
Here's how to use an existing access token for the request, thus no re-authorization client is needed:
use kamermans\GuzzleOAuth2\OAuth2Subscriber; // Setup OAuth $oauth = new OAuth2Subscriber(); // Manually specify access_token. When it expires, you will get an exception $oauth->getTokenData()->accessToken = 'somelongtoken'; $client = new GuzzleHttp\Client(); // Attach OAuth subscriber to the Guzzle client and all URLs will be authenticated $client->getEmitter()->attach($oauth); $response = $client->get('http://somehost/some_secure_url'); echo "Status: ".$response->getStatusCode()."\n";
Client Credentials Method
Client credentials are normally used in server-to-server authentication. With this grant type, a client is requesting authorization in its own behalf, so there are only two parties involved. At a minimum, a client_id and client_secret are required, although many services require a scope and other parameters.
Here's an example of the client credentials method:
use kamermans\GuzzleOAuth2\GrantType\ClientCredentials; use kamermans\GuzzleOAuth2\OAuth2Subscriber; // Authorization client - this is used to request OAuth access tokens $reauth_client = new GuzzleHttp\Client([ // URL for access_token request 'base_url' => 'http://some_host/access_token_request_url', ]); $reauth_config = [ "client_id" => "your client id", "client_secret" => "your client secret", "scope" => "your scope(s)", // optional "state" => time(), // optional ]; $grant_type = new ClientCredentials($reauth_client, $reauth_config); $oauth = new OAuth2Subscriber($grant_type); // This is the normal Guzzle client that you use in your application $client = new GuzzleHttp\Client(); $client->getEmitter()->attach($oauth); $response = $client->get('http://somehost/some_secure_url'); echo "Status: ".$response->getStatusCode()."\n";
qbnk/guzzle5-oauth2-subscriber 适用场景与选型建议
qbnk/guzzle5-oauth2-subscriber 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.19k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth」 「oauth2」 「Guzzle」 「provider」 「subscriber」 「guzzle5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 qbnk/guzzle5-oauth2-subscriber 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 qbnk/guzzle5-oauth2-subscriber 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 qbnk/guzzle5-oauth2-subscriber 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Email Toolkit Plugin for CakePHP
Cloudflare Middleware For Guzzle
统计信息
- 总下载量: 10.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-05