ohmy / auth
此包已废弃,不再维护。未建议替代包。
OAuth如此简单..你甚至不会相信它是OAuth
0.0.7
2014-04-13 06:34 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2020-09-04 18:32:47 UTC
README
ohmy-auth (Oma) 是一个PHP库,它将OAuth简化为流畅的接口
use ohmy\Auth1; Auth1::legs(2) ->set('key', 'key') ->set('secret', 'secret') ->request('http://term.ie/oauth/example/request_token.php') ->access('http://term.ie/oauth/example/access_token.php') ->GET('http://term.ie/oauth/example/echo_api.php') ->then(function($data) { # got data });
依赖
Oma仅需要PHP (>= 5.3) 和Curl(curl_init(),curl_setopt()等)的常规扩展、JSON(json_encode(),json_decode())以及session(session_start(),session_destroy())。
使用Composer安装
安装Oma的最佳方式是通过Composer。只需将ohmy/auth
添加到项目的composer.json
中,然后运行composer install
。例如
{ "require": { "ohmy/auth": "*" } }
手动安装
如果您不希望使用Composer,可以下载存档或克隆此存储库,然后将src/ohmy
放入您的项目设置中。
双因素OAuth 1.0a
use ohmy\Auth1; # do 2-legged oauth $termie = Auth1::legs(2) # configuration ->set('key', 'key') ->set('secret', 'secret') # oauth flow ->request('http://term.ie/oauth/example/request_token.php') ->access('http://term.ie/oauth/example/access_token.php'); # api call $termie->GET('http://term.ie/oauth/example/echo_api.php') ->then(function($data) { # got data });
三因素OAuth 1.0a
注意:此功能需要会话来在重定向之间保存数据。没有会话则无法正常工作!
use ohmy\Auth1; # do 3-legged oauth $tumblr = Auth1::legs(3) # configuration ->set(array( 'consumer_key' => 'your_consumer_key', 'consumer_secret' => 'your_consumer_secret', 'callback' => 'your_callback_url' )) # oauth flow ->request('http://www.tumblr.com/oauth/request_token') ->authorize('http://www.tumblr.com/oauth/authorize') ->access('http://www.tumblr.com/oauth/access_token'); # access tumblr api $tumblr->GET('https://api.tumblr.com/v2/user/info') ->then(function($data) { # got user data });
三因素OAuth 2.0
use ohmy\Auth2; # do 3-legged oauth $github = Auth2::legs(3) # configuration ->set(array( 'id' => 'your_github_client_id', 'secret' => 'your_github_client_secret', 'redirect' => 'your_redirect_uri' )) # oauth flow ->authorize('https://github.com/login/oauth/authorize') ->access('https://github.com/login/oauth/access_token') ->finally(function($data) use(&$access_token) { $access_token = $data['access_token']; }); # access github api $github->GET("https://api.github.com/user?access_token=$access_token", null, array('User-Agent' => 'ohmy-auth')) ->then(function($data) { # got user data });
更多示例
许可证
- PHP许可证:PHP许可证
- ohmy-auth:新BSD许可证。