indibeast / oauth2-human
Human OAuth 2.0 support for the PHP League's OAuth 2.0 Client
dev-master
2016-02-09 10:22 UTC
Requires
- php: >=5.5.0
- league/oauth2-client: ~1.0@dev
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-11-13 08:38:29 UTC
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.