2017 © Pedro Peláez
 

library oauth2-wrike

Wrike OAuth 2.0 support for the PHP League's OAuth 2.0 Client

image

michaelkaefer/oauth2-wrike

Wrike OAuth 2.0 support for the PHP League's OAuth 2.0 Client

  • Thursday, July 12, 2018
  • by michaelKaefer
  • Repository
  • 1 Watchers
  • 0 Stars
  • 94 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 12 % Grown

The README.md

Wrike Provider for OAuth 2.0 Client

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

NOTE: since 2.x only Wrike's v4 API is supported (prior versions support Wrike's v3 API), (*2)

Installation

composer require michaelkaefer/oauth2-wrike

Usage

$wrikeProvider = new \MichaelKaefer\OAuth2\Client\Provider\Wrike([
    'clientId'                => 'yourId',    // The client ID assigned to you by Wrike
    'clientSecret'            => 'yourSecret',   // The client password assigned to you by the provider
    'redirectUri'             => ''
]);

// Get authorization code
if (!isset($_GET['code'])) {
    // Get authorization URL
    $authorizationUrl = $wrikeProvider->getAuthorizationUrl();

    // Get state and store it to the session
    $_SESSION['oauth2state'] = $wrikeProvider->getState();

    // Redirect user to authorization URL
    header('Location: ' . $authorizationUrl);
    exit;
// Check for errors
} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) {
    if (isset($_SESSION['oauth2state'])) {
        unset($_SESSION['oauth2state']);
    }
    exit('Invalid state');
} else {
    // Get access token
    try {
        $accessToken = $wrikeProvider->getAccessToken(
            'authorization_code',
            [
                'code' => $_GET['code']
            ]
        );
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }

    // Get resource owner
    try {
        $resourceOwner = $wrikeProvider->getResourceOwner($accessToken);
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }

    // Now you can store the results to session ...
    $_SESSION['accessToken'] = $accessToken;
    $_SESSION['resourceOwner'] = $resourceOwner;

    // ... or do some API request
    $folderId = 'yourFolderId';
    $request = $wrikeProvider->getAuthenticatedRequest(
        'GET',
        'https://www.wrike.com/api/v3/folders/' . $folderId . '/folders',
        $accessToken
    );
    try {
        $response = $wrikeProvider->getParsedResponse($request);
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }
    var_dump($response['data']);
}

For more information see the PHP League's general usage examples., (*3)

Testing

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

License

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

The Versions

12/07 2018

dev-master

9999999-dev

Wrike OAuth 2.0 support for the PHP League's OAuth 2.0 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Käfer

api authentication authorization php oauth client oauth2 wrike

15/04 2018

v1.0.2

1.0.2.0

Wrike OAuth 2.0 support for the PHP League's OAuth 2.0 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Käfer

api authentication authorization php oauth client oauth2 wrike

12/08 2017

v1.0.1

1.0.1.0

Wrike OAuth 2.0 support for the PHP League's OAuth 2.0 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Käfer

api authentication authorization php oauth client oauth2 wrike

23/07 2017

v1.0.0

1.0.0.0

Wrike OAuth 2.0 support for the PHP League's OAuth 2.0 Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Käfer

authentication authorization oauth client oauth2 wrike