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

This package is not auto-updated.

Last update: 2024-11-01 20:13:07 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Build Status

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();
}