2017 © Pedro Peláez
 

library oauth2-dailymotion

Dailymotion 2.0 Client Provider for The PHP League OAuth2-Client

image

wolftotem4/oauth2-dailymotion

Dailymotion 2.0 Client Provider for The PHP League OAuth2-Client

  • Friday, January 19, 2018
  • by wolftotem4
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 15 % Grown

The README.md

Dailymotion Provider for OAuth 2.0 Client

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

Requirements

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

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • PHP 8.0
  • PHP 8.1

Installation

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

{
    "require": {
        "wolftotem4/oauth2-dailymotion": "^0.9.1"
    }
}

Usage

Authorization Code Flow

session_start();

$provider = new \WTotem4\OAuth2\Client\Provider\Dailymotion([
    'clientId'          => '{dailymotion-app-key}',
    'clientSecret'      => '{dailymotion-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' => ['email', '...', '...'],
    ]);
    $_SESSION['oauth2state'] = $provider->getState();

    echo '<a href="'.$authUrl.'">Log in with Dailymotion!</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 user's details
    $user = $provider->getResourceOwner($token);

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

    echo '<pre>';
    var_dump($user);
    # object(WTotem4\OAuth2\Client\Provider\DailymotionUser)#10 (1) { ...
    echo '</pre>';

} catch (\Exception $e) {

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

echo '

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

// The time (in epoch time) when an access token will expire
var_dump($token->getExpires());
# int(1515911929)
echo '
';

The Versions

19/01 2018

dev-master

9999999-dev

Dailymotion 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 dailymotion

19/01 2018

v0.9.2

0.9.2.0

Dailymotion 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 dailymotion

15/11 2017

v0.9.1

0.9.1.0

Dailymotion 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 dailymotion

15/11 2017

v0.9.0

0.9.0.0

Dailymotion 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authentication authorization oauth client oauth2 dailymotion

14/11 2017

v0.0.1

0.0.1.0

Dailymotion 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

authentication authorization oauth client oauth2 dailymotion