2017 © Pedro Peláez
 

library oauth-client

PHP OAuth Client based on lusitanian/oauth

image

maye/oauth-client

PHP OAuth Client based on lusitanian/oauth

  • Wednesday, November 9, 2016
  • by kawanamiyuu
  • Repository
  • 2 Watchers
  • 1 Stars
  • 1,460 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 1 % Grown

The README.md

Maye.OAuthClient

Build Status, (*1)

Maye.OAuthClient is the OAuth Client library which has simple interface to support OAuth 1 and OAuth 2, based on lusitanian/oauth (PHPoAuthLib)., (*2)

e.g. Twitter (OAuth1)

1. Redirects to an authorization page

use Maye\OAuthClient;

define('CONSUMER_KEY', 'your twitter consumer key');
define('CONSUMER_SECRET', 'your twitter consumer secret');

$client = new OAuth1Client(
    'twitter', 
    CONSUMER_KEY, 
    CONSUMER_SECRET, 
    '/oauth/twitter/callback'
);

// redirect
$client->authorize();
exit;

2. Called back after authorization process finished

$denied = $_GET['denied'];
$oauthToken = $_GET['oauth_token'];
$oauthVerifier = $_GET['oauth_verifier'];

if (!empty($denied)) {
    // should be handled as error
    echo 'error';
    exit;
}

/** @var OAuth\OAuth1\Token\TokenInterface $token */
$token = $client->requestAccessToken($oauthToken, $oauthVerifier);

$accessToken       = $token->getAccessToken();
$accessTokenSecret = $token->getAccessTokenSecret();
$userId     = $token->getExtraParams()['user_id'];
$screenName = $token->getExtraParams()['screen_name'];

// gets the authorized user info
$result = $client->api('get', 'users/show.json', ['user_id' => $userId]);
$result = json_decode($result);

$name = $result->name;

e.g. Facebook (OAuth2)

1. Redirects to authorization page

use Maye\OAuthClient;
use OAuth\OAuth2\Service\Facebook;

define('CONSUMER_KEY', 'your facebook consumer key');
define('CONSUMER_SECRET', 'your facebook consumer secret');

$client = new OAuth2Client(
    'facebook',
    CONSUMER_KEY, 
    CONSUMER_SECRET, 
    '/oauth/facebook/callback',
    [Facebook::SCOPE_READ_STREAM, Facebook::SCOPE_PUBLISH_ACTIONS]
);

// redirect
$client->authorize();
exit;

2. Called back after authorization process finished

$code = $_GET['code'];

if (empty($code)) {
    // should be handled as error
    echo 'error';
    exit;
}

/** @var OAuth\OAuth2\Token\TokenInterface $token */
$token = $client->requestAccessToken($code);

$accessToken  = $token->getAccessToken();
$refreshToken = $token->getRefreshToken();

// gets the authorized user info
$result = $client->api('get', '/me');
$result = json_decode($result);

$id = $result->id;
$name = $result->name;

The Versions

09/11 2016

dev-master

9999999-dev

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth

09/11 2016

1.4.0

1.4.0.0

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth

14/06 2016

1.3.0

1.3.0.0

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth

12/03 2015

1.2.0

1.2.0.0

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth

11/03 2015

1.1.1

1.1.1.0

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth

18/02 2015

1.1.0

1.1.0.0

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth

14/02 2015

1.0.1

1.0.1.0

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth

14/02 2015

1.0.0

1.0.0.0

PHP OAuth Client based on lusitanian/oauth

  Sources   Download

MIT

The Requires

 

The Development Requires

by Yuu Kawanami

oauth