tonoman3g/oauth1-server
Composer 安装命令:
composer require tonoman3g/oauth1-server
包简介
README 文档
README
#OAuth PSR2 Compliant OAuth 1.0 library base on Andy Smith's OAuth library found here: http://oauth.googlecode.com/svn/code/php/
##2-Legged OAuth Server Example
$request = JoakimKejser\OAuth\OauthRequest::createFromGlobals(); // Simple Example ConsumerStore using arrays $consumerStore = new JoakimKejser\OAuth\ConsumerStore\ArrayConsumerStore(array('key' => 'secret', 'key2' => 'secret2')); // Simple Example NonceStore using arrays - you should use a persistent store $nonceStore = new JoakimKejser\OAuth\NonceStore\ArrayNonceStore(); // We don't need a TokenStore since we'll be doing Two Legged $server = new JoakimKejser\OAuth\Server($request, $consumerStore, $nonceStore, null); // Add the signature method you wanna support $server->addSignatureMethod(new JoakimKejser\OAuth\SignatureMethod\HmacSha1); try { list($consumer, $token) = $server->verifyRequest(); echo "Welcome consumer with key: " . $consumer->key; } catch (JoakimKejser\OAuth\Exception $e) { echo "Something went wrong: " . $e->getMessage(); }
##2-Legged OAuth Client Example
$key = 'key'; $secret = 'secret'; $consumer = new JoakimKejser\OAuth\Consumer($key, $secret); $sigMethod = new JoakimKejser\OAuth\SignatureMethod\HmacSha1; $method = "POST"; //API endpoint to call $api_endpoint = 'http://apiyouwanna/call'; //Create and sign the request - 2-Legged so token is null $req = OauthRequest::createFromConsumerAndToken($consumer, $method, $api_endpoint, null); $req->sign($sigMethod, $consumer, null); //Token is still null $ch = curl_init(); $url = $req->getNormalizedHttpUrl(); // Get the URL for the GET request, without oauth parameters, as we'll add them to the Authorization header if ($method == "GET") { $url = $req->toUrl(true); } // Set up CURL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Add the Authorization header to the request curl_setopt($ch, CURLOPT_HTTPHEADER, array($req->toHeader())); // If it's post, add the post data if ($method == "POST") { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req->toPostData(true)); } // And go $output = curl_exec($ch); curl_close($ch); echo $output;
tonoman3g/oauth1-server 适用场景与选型建议
tonoman3g/oauth1-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.55k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tonoman3g/oauth1-server 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tonoman3g/oauth1-server 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 17.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-06-10