slickplan / oauth2-slickplan-php
Slickplan.com OAuth 2.0 Client Provider for The PHP League OAuth2-Client
1.0.0
2022-06-21 13:39 UTC
Requires
- php: ^7.4 || ^8.0
- league/oauth2-client: ^2.6.1
README
This package provides Slickplan OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
Slickplan API documentation: slickplan/api-docs
Installation
To install, use composer:
composer require slickplan/oauth2-slickplan-php
Usage
Please refer to League's Oauth Client documentation.
Example code:
use Slickplan\OAuth2\Client\Provider\Slickplan as SlickplanProvider; $provider = new SlickplanProvider([ 'clientId' => '{client-id}', 'clientSecret' => '{client-secret}', 'redirectUri' => 'https://example.com/slickplan/redirect-uri/', ]); if (isset($_GET['error'])) { print_r($_GET); exit; } elseif (!isset($_GET['code'])) { header('Location: ' . $provider->getAuthorizationUrl(['scope' => 'all_read'])); exit; } try { $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'], ]); $user = $provider->getResourceOwner($token); } catch (Exception $e) { exit('Error: ' . $e->getMessage()); } echo 'Hello ' . $user->getFirstName() . '!<br>'; echo 'Your API token: <code>' . $token->getToken() . '</code>';