pabloprieto / oauth2
一个简单的OAuth2客户端,与Zend\Http协同工作
dev-master
2014-04-18 09:13 UTC
Requires
- php: >=5.3.0
- zendframework/zend-http: 2.*
This package is not auto-updated.
Last update: 2024-09-24 07:30:23 UTC
README
一个简单的OAuth2客户端,与Zend\Http协同工作
使用Google+ API的示例
$googleClient = new OAuth2\Client('YOUR_API_KEY', 'YOUR_API_SECRET');
$redirectUri = 'http://domain/redirect-uri';
if (isset($_GET['code'])) {
$params = array(
'code' => $_GET['code'],
'redirect_uri' => $redirectUri,
);
$response = $googleClient->getAccessToken(
'https://#/o/oauth2/token',
OAuth2\Client::GRANT_TYPE_AUTH_CODE,
$params
);
$token = json_decode($response);
$googleClient->setAccessToken($token->access_token)
$response = $googleClient->fetch('https://www.googleapis.com/plus/v1/people/me');
var_dump(json_decode($response->getBody()));
} else {
$scopes = array(
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/plus.me'
);
$params = array(
'state' => uniqid('', true),
'redirect_uri' => $redirectUri,
'scope' => implode(' ', $scopes)
);
$authUrl = $googleClient->getAuthenticationUrl('https://#/o/oauth2/auth', $params);
header('Location: ' . $authUrl);
exit;
}
许可证
在MIT许可证下发布
联系方式
Pablo Prieto, pabloprieto.net