indibeast/oauth2-human
Composer 安装命令:
composer require indibeast/oauth2-human
包简介
Human OAuth 2.0 support for the PHP League's OAuth 2.0 Client
README 文档
README
This package provides Human OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
Usage
Authorization Code Flow
$provider = new \Human\OAuth2\Client\Provider\Human([ 'clientId' => 'XXXXXXXX', 'clientSecret' => 'XXXXXXXX', 'redirectUri' => 'https://your-registered-redirect-uri/', 'account' => 'XXXXX' ]); if (!isset($_GET['code'])) { $authurl = $provider->getAuthorizationUrl(); $_SESSION['oauth2state'] = $provider->getState(); header('Location: '.$authUrl); exit; } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])){ unset($_SESSION['oauth2state']); exit('Invalid state'); } else { $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); try { $client = new Client($token); $user = $client->getResourceOwner(); echo $user->getFirstName(); } catch (Exception $e) { echo "Oops!..." } }
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 92
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-23