shippinno / oauth2-next-engine
Next Engine OAuth 2.0 Client Provider for The PHP League OAuth2-Client
0.0.1
2017-06-07 15:38 UTC
Requires
- php: >=5.6.0
- league/oauth2-client: ^2.2
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-12-13 20:40:18 UTC
README
This package provides Resource Next Engine OAuth 2.0 support for the PHP League’s OAuth 2.0 Client.
Installation
To install, use composer:
composer require w-takumi/oauth2-next-engine
Usage
Usage is the same as The League’s OAuth client, using \Shippinno\NextEngine\OAuth2\Client\Provider\NextEngineProvider
as the provider.
Authorization Code Flow
<?php $provider = new \Shippinno\NextEngine\OAuth2\Client\Provider\NextEngineProvider([ 'clientId' => '{next-engine-client-id}', 'clientSecret' => '{next-engine-lient-secret}', 'redirectUri' => 'https://example.com/callback', ]); if (!isset($_GET['uid']) || !isset($_GET['state'])) { $authUrl = $provider->getAuthorizationUrl(); header('Location: '.$authUrl); exit; } else { $token = $nextEngineProvider->getAccessToken('client_credentials', [ 'uid' => $_GET['uid'], 'state' => $_GET['state'] ]); try { $user = $provider->getResourceOwner($token); printf('Hello %s!', $user->getCompanyName()); } catch (Exception $e) { exit('Oh dear...'); } echo $token->getToken(); }