slince / oauth
slince oauth library
dev-master
2015-06-21 06:53 UTC
Requires
- php: ~5.4
- guzzlehttp/guzzle: ~5.2.0
This package is not auto-updated.
Last update: 2024-11-23 17:47:27 UTC
README
oauth是对oAuth2.0协议的封装支持,如果您对oAuth2.0不了解的话,可以参考http://oauth.net/2/;通过oauth您可以方便的获取登录用户的信息以及服务商提供的其它资料和服务;
##目前支持的服务
- baidu
(后续还在增加中)
使用方式
use Slince\OAuth\Certificate\Certificate;
use Slince\OAuth\ServiceFactory;
use Slince\OAuth\Token\Token;
$certificate = new Certificate(
client id,
client secret,
callbackurl
);
$token = new Token();
$baidu = ServiceFactory::get('baidu', $certificate, $token);
if (empty($_GET['code'])) {
echo $location = $baidu->getAuthorizeUrl();
header("location: {$location}");
} else {
$token = $baidu->requestToken($_GET['code']);
echo $token->getAccessToken();
$token = $baidu->refreshToken($token);
echo $token->getAccessToken();
$user = $baidu->request('passport/users/getInfo');
print_r($user);
}
详细使用方式请参考demo下的案例