shadowhand / oauth2-untappd
为 PHP League OAuth2-Client 提供的 Untappd OAuth 2.0 客户端提供者
0.3.0
2016-03-08 14:12 UTC
Requires
- league/oauth2-client: ^1.0.0
Requires (Dev)
- mockery/mockery: ^0.9.4
README
本软件包为 PHP League 的 OAuth 2.0 客户端 提供Untappd OAuth 2.0 支持。
本软件包遵循 PSR-1、PSR-2 和 PSR-4。如果发现符合性疏忽,请通过 pull request 提交补丁。
需求
以下版本的 PHP 受支持。
- PHP 5.5
- PHP 5.6
- PHP 7.0
- HHVM
安装
要安装,请使用 composer
composer require shadowhand/oauth2-untappd
使用方法
授权码流程
$provider = new Shadowhand\OAuth2\Client\Provider\Untappd([ 'clientId' => '{untappd-app-id}', 'clientSecret' => '{untappd-app-secret}', 'redirectUri' => 'https://example.com/callback-url', 'hostedDomain' => 'example.com', ]); if (!empty($_GET['error'])) { // Got an error, probably user denied access exit('Got error: ' . $_GET['error']); } elseif (empty($_GET['code'])) { // If we don't have an authorization code then get one $authUrl = $provider->getAuthorizationUrl(); header('Location: ' . $authUrl); exit; } else { // Try to get an access token (using the authorization code grant) $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); // Optional: Now you have a token you can look up a users profile data try { // We got an access token, let's now get the owner details $ownerDetails = $provider->getResourceOwner($token); // Use these details to create a new profile printf('Hello %s!', $ownerDetails->getFirstName()); } catch (Exception $e) { // Failed to get user details exit('Something went wrong: ' . $e->getMessage()); } // Use this to interact with an API on the users behalf echo $token->accessToken; }
注意:Untappd 不支持通过 state
传递进行验证。
刷新令牌
Untappd 令牌不会过期,也不需要刷新。
测试
$ ./vendor/bin/phpunit
贡献
请参阅 CONTRIBUTING 以获取详细信息。
鸣谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。