2017 © Pedro Peláez
 

library oauth2-vend

Vend OAuth 2.0 Client Provider for The PHP League OAuth2-Client

image

ursuleacv/oauth2-vend

Vend OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  • Thursday, May 19, 2016
  • by ursuleacv
  • Repository
  • 1 Watchers
  • 1 Stars
  • 673 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

Vend Provider for OAuth 2.0 Client

Build Status, (*1)

This package provides Vend OAuth 2.0 support for the PHP League's OAuth 2.0 Client., (*2)

This package is compliant with PSR-1, PSR-2, PSR-4, and PSR-7. If you notice compliance oversights, please send a patch via pull request., (*3)

Requirements

The following versions of PHP are supported., (*4)

  • PHP 7.0
  • PHP 7.1
  • PHP 7.2
  • HHVM

Installation

Add the following to your composer.json file., (*5)

{
    "require": {
        "ursuleacv/oauth2-vend": "~1.0"
    }
}

Usage

Authorization Code Flow

session_start();

$provider = new League\OAuth2\Client\Provider\Vend([
    'clientId' => CLIENT_ID,
    'clientSecret' => CLIENT_SECRET,
    'redirectUri' => REDIRECT_URI,
    'storeName' => STORE_NAME,
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl([]);
    $_SESSION['oauth2state'] = $provider->getState();

    echo '<a href="'.$authUrl.'">Log in with Vend!</a>';
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    echo 'Invalid state.';
    exit;

}

// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
    'code' => $_GET['code']
]);

try {

    // We got an access token, let's make some requests
    $vendApi = $provider->vendApi($token);
    $sale = $vendApi->getSale(1);
    $registers = $vendApi->getRegisters();

    echo '<pre>';
    print_r($sale);
    echo '</pre>';

} catch (Exception $e) {
    exit($e->getMessage());
}

echo '

';
// Use this to interact with the API on the client behalf
var_dump($token->getToken());

echo '
';

Testing

bash $ ./vendor/bin/phpunit, (*6)

Contributing

Please see CONTRIBUTING for details., (*7)

Credits

License

The MIT License (MIT). Please see License File for more information., (*8)

The Versions

19/05 2016

dev-master

9999999-dev

Vend OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 vend

19/05 2016

v1.0.2

1.0.2.0

Vend OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 vend

18/05 2016

v1.0.1

1.0.1.0

Vend OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 vend

24/04 2016

1.0.0

1.0.0.0

Vend OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 vend