2017 © Pedro Peláez
 

library oauth2-cronofy

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

image

geekdevs/oauth2-cronofy

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

  • Thursday, January 25, 2018
  • by geekdevs
  • Repository
  • 2 Watchers
  • 2 Stars
  • 6,891 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 2 % Grown

The README.md

Cronofy Provider for OAuth 2.0 Client

Build Status Latest Stable Version, (*1)

This package provides Cronofy Calendar 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.4

Installation

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

{
    "require": {
        "geekdevs/oauth2-cronofy": "^2.0"
    }
}

Usage

Authorization Code Flow

session_start();

$provider = new Geekdevs\OAuth2\Client\Provider\Cronofy([
    'clientId'          => '{cronofy-app-id}',
    'clientSecret'      => '{cronofy-app-secret}',
    'redirectUri'       => 'https://example.com/callback-url'
]);

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

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

    echo '<a href="'.$authUrl.'">Log in with Cronofy!</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']
]);

// Optional: Now you have a token you can look up a users profile data
try {

    // We got an access token, let's now get the account's details
    $account = $provider->getResourceOwner($token);

    // Use these details to create a new profile
    printf('Hello %s!', $account->getName());

    echo '<pre>';
    var_dump($account);
    # object(League\OAuth2\Client\Provider\CronofyAccount)#10 (1) { ...
    echo '</pre>';

} catch (Exception $e) {

    // Failed to get account details
    exit('Oh dear...');
}

echo '

';
// Use this to interact with an API on the users behalf
var_dump($token->getToken());
# string(217) "CAADAppfn3msBAI7tZBLWg...

// Number of seconds until the access token will expire, and need refreshing
var_dump($token->getExpires());
# int(1436825866)
echo '
';

The CronofyAccount Entity

When using the getResourceOwner() method to obtain the account details, it will be returned as a CronofyAccount entity., (*6)

$account = $provider->getResourceOwner($token);

$id = $account->getId();
var_dump($id);
# string(1) "acc_567236000909002"

$name = $account->getName();
var_dump($name);
# string(15) "Pavel Dubinin"

$email = $account->getEmail();
var_dump($email);
# string(15) "geekevs@gmail.com"

$timezone = $account->getDefaultTimezone();
var_dump($timezone);
# string(15) "Europe/London"

You can also get all the data from the Account node as a plain-old PHP array with toArray()., (*7)

$accountData = $account->toArray();

Testing

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

Contributing

Please see CONTRIBUTING for details., (*9)

Credits

License

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

The Versions

25/01 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

25/01 2018

1.1.3

1.1.3.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

25/01 2018

1.1.2

1.1.2.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

22/10 2017

1.1.1

1.1.1.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

22/10 2017

1.1.0

1.1.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

17/11 2016

dev-dev

dev-dev

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

05/10 2016

1.0.1

1.0.1.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

12/09 2016

1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

02/08 2016

0.3.0

0.3.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

02/08 2016

0.2.0

0.2.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy

23/03 2016

0.1.0

0.1.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Dubinin

authentication authorization oauth calendar client oauth2 cronofy