ray/oauth-module
Composer 安装命令:
composer require ray/oauth-module
包简介
OAuth module for Ray.Di
README 文档
README
Installation
Composer install
$ composer require ray/oauth-module
Module install
use Ray\Di\AbstractModule; use Ray\OAuthModule\OAuth1Module; use Ray\OAuthModule\OAuth1Service; class AppModule extends AbstractModule { protected function configure() { $this->install(new OAuth1Module(OAuth1Service::TWITTER, $_ENV['CONSUMER_KEY'], $_ENV['CONSUMER_SECRET'], '/oauth/callback')); } }
Usage
Redirects to the authorization page.
use Ray\OAuthModule\Inject\TwitterOAuthInject; class OAuthController { use TwitterOAuthInject; public function redirectAction() { $this->twitterOAuth->authorize(); } }
Requests the AccessToken. This is callback process after authorization finished.
use Ray\OAuthModule\Inject\TwitterOAuthInject; class OAuthController { use TwitterOAuthInject; public function callbackAction() { if ($_GET['denied']) { // should be handled as error return 'ERROR'; } // requests AccessToken $token = $this->twitterOAuth->requestAccessToken($_GET['oauth_token'], $_GET['oauth_verifier']); /** @var OAuth\OAuth1\Token\TokenInterface $token */ // $accessToken = $token->getAccessToken(); // $accessTokenSecret = $token->getAccessTokenSecret(); $userId = $token->getExtraParams()['user_id']; $screenName = $token->getExtraParams()['screen_name']; // gets authorized user info $user = $this->twitterOAuth->api('get', 'users/show.json', ['user_id' => $userId]); $user = json_decode($user); $result = 'user_id : ' . $userId .'<br />'; $result.= 'screen_name : @' . $screenName . '<br />'; $result.= 'name: ' . $user->name; return $result; } }
Demo
OAuth1 (Twitter)
See docs/demo/www/oauth1_twitter.php for detail.
# 1. Create and configure the Twitter App on Developer Website # 2. Set Consumer Key and Secret in docs/demo/www/oauth1_twitter.php # 3. Start the PHP built-in Web-Server $ php -S localhost:8080 -t docs/demo/www # 4. Access http://localhost:8080/oauth1_twitter.php << output >> user_id: {Your User ID} screen_name: @{your_screen_name} name: {Your Name}
OAuth2 (Facebook)
See docs/demo/www/oauth2_facebook.php for detail.
# 1. Create and configure the Facebook App on Developer Website # 2. Set App ID and Secret in docs/demo/www/oauth2_facebook.php # 3. Start the PHP built-in Web-Server $ php -S localhost:8080 -t docs/demo/www # 4. Access http://localhost:8080/oauth2_facebook.php << output >> id: {Your ID} name: {Your Name}
ray/oauth-module 适用场景与选型建议
ray/oauth-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.3k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth」 「Ray.Di」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ray/oauth-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ray/oauth-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ray/oauth-module 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
aura/web module for Ray.Di
Validation module for Ray.Di
WeChat OAuth SDK
Web Form module for Ray.Di
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
统计信息
- 总下载量: 1.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-05