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

This package is auto-updated.

Last update: 2024-11-27 18:07:49 UTC


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>';