Skip to content

Commit

Permalink
Merge pull request #5 from timothyasp/master
Browse files Browse the repository at this point in the history
Fix composer install; Upgrade to v2 of league/oauth
  • Loading branch information
hayageek authored Oct 30, 2018
2 parents 089ec1d + c26058a commit 57fb5b9
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 78 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

This package provides Yahoo OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

This package is compliant with [PSR-1][], [PSR-2][] and [PSR-4][]. If you notice compliance oversights, please send
This package is compliant with [PSR-1](https://www.php-fig.org/psr/psr-1/), [PSR-2](https://www.php-fig.org/psr/psr-2/) and [PSR-4](https://www.php-fig.org/psr/psr-4/). If you notice compliance oversights, please send
a patch via pull request.


## Requirements

The following versions of PHP are supported.

* PHP 5.5
* PHP 5.6
* PHP 7.0
* PHP 7.1
* HHVM

## Installation
Expand Down Expand Up @@ -148,7 +148,6 @@ $ ./vendor/bin/phpunit
- [Ravishanker Kusuma](https://github.com/hayageek/)



## License

The MIT License (MIT). Please see [License File](https://github.com/hayageek/oauth2-yahoo/blob/master/LICENSE) for more information.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"name": "Ravishanker Kusuma",
"email": "[email protected]",
"homepage": "http://hayageek.com"
},
{
"name": "Timothy Asp",
"email": "[email protected]"
}
],
"keywords": [
Expand All @@ -20,7 +24,7 @@
"minimum-stability": "dev",
"prefer-stable" : true,
"require": {
"league/oauth2-client": "^1.0"
"league/oauth2-client": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// Replace these with your token settings
// Create a project at https://developer.yahoo.com/apps

$clientId = '<your_client_id>';
$clientId = '<your_client_id>';
$clientSecret = '<yout_client_secret>';
// Change this if you are not using the built-in PHP server
$redirectUri = 'http://myapp.com/index.php';
$redirectUri = 'http://myapp.com/index.php';

// Start the session
session_start();
Expand Down
26 changes: 13 additions & 13 deletions examples/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@


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

// Use these details to create a new profile

echo 'Name: '.$ownerDetails->getName()."<br>";
echo 'FirstName: '.$ownerDetails->getFirstName()."<br>";
echo 'Lastname: '.$ownerDetails->getLastName()."<br>";
echo 'Email: '.$ownerDetails->getEmail()."<br>";
echo 'Image: '.$ownerDetails->getAvatar()."<br>";
echo 'Name: ' . $ownerDetails->getName() . "<br>";
echo 'FirstName: ' . $ownerDetails->getFirstName() . "<br>";
echo 'Lastname: ' . $ownerDetails->getLastName() . "<br>";

echo 'Email: ' . $ownerDetails->getEmail() . "<br>";
echo 'Image: ' . $ownerDetails->getAvatar() . "<br>";

} catch (Exception $e) {

Expand All @@ -35,13 +35,13 @@


// Use this to interact with an API on the users behalf
echo "Token: ". $token->getToken()."<br>";
echo "Token: " . $token->getToken() . "<br>";

// Use this to get a new access token if the old one expires
echo "Refresh Token: ".$token->getRefreshToken()."<br>";
echo "Refresh Token: " . $token->getRefreshToken() . "<br>";

// Number of seconds until the access token will expire, and need refreshing
echo "Expires:" .$token->getExpires()."<br>";
echo "Expires:" . $token->getExpires() . "<br>";


echo "After Refreshing Token <br>";
Expand All @@ -50,10 +50,10 @@
$token = $provider->getAccessToken($grant, ['refresh_token' => $token->getRefreshToken()]);

// Use this to interact with an API on the users behalf
echo "Token: ". $token->getToken()."<br>";
echo "Token: " . $token->getToken() . "<br>";

// Use this to get a new access token if the old one expires
echo "Refresh Token: ".$token->getRefreshToken()."<br>";
echo "Refresh Token: " . $token->getRefreshToken() . "<br>";

// Number of seconds until the access token will expire, and need refreshing
echo "Expires:" .$token->getExpires()."<br>";
echo "Expires:" . $token->getExpires() . "<br>";
57 changes: 26 additions & 31 deletions src/Provider/Yahoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class Yahoo extends AbstractProvider

const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'xoauth_yahoo_guid';


/*
https://developer.yahoo.com/oauth2/guide/flows_authcode/#step-2-get-an-authorization-url-and-authorize-access
*/
protected $language = "en-us";

private $imageSize='192x192';

private $imageSize = '192x192';

public function getBaseAuthorizationUrl()
{
Expand All @@ -35,30 +33,29 @@ public function getBaseAccessTokenUrl(array $params)

public function getResourceOwnerDetailsUrl(AccessToken $token)
{

$guid = $token->getResourceOwnerId();
return 'https://social.yahooapis.com/v1/user/'.$guid.'/profile?format=json';

return 'https://social.yahooapis.com/v1/user/' . $guid . '/profile?format=json';
}

/**
* Get user image from provider
*
* @param array $response
* @param AccessToken $token
* @param array $response
* @param AccessToken $token
*
* @return array
*/
protected function getUserImage(array $response, AccessToken $token)
{
$guid = $token->getResourceOwnerId();
$url = 'https://social.yahooapis.com/v1/user/'.$guid.'/profile/image/'.$this->imageSize.'?format=json';

$url = 'https://social.yahooapis.com/v1/user/' . $guid . '/profile/image/' . $this->imageSize . '?format=json';

$request = $this->getAuthenticatedRequest('get', $url, $token);

$response = $this->getResponse($request);

return $response;
}

Expand All @@ -73,9 +70,9 @@ protected function getAuthorizationParameters(array $options)

protected function getDefaultScopes()
{
/*
No scope is required. scopes are part of APP Settings.
*/
/*
No scope is required. scopes are part of APP Settings.
*/
return [];
}

Expand All @@ -86,16 +83,15 @@ protected function getScopeSeparator()

protected function checkResponse(ResponseInterface $response, $data)
{

if (!empty($data['error'])) {
$code = 0;
$code = 0;
$error = $data['error'];

if (is_array($error)) {
/*
No code is returned in the error
*/
$code = -1;
/*
No code is returned in the error
*/
$code = -1;
$error = $error['description'];
}
throw new IdentityProviderException($error, $code, $data);
Expand All @@ -105,25 +101,24 @@ protected function checkResponse(ResponseInterface $response, $data)
protected function createResourceOwner(array $response, AccessToken $token)
{
$user = new YahooUser($response);

$imageUrl = $this->getUserImageUrl($response, $token);

return $user->setImageURL($imageUrl);

}

/**
* Get user image url from provider, if available
*
* @param array $response
* @param AccessToken $token
* @param array $response
* @param AccessToken $token
*
* @return string
*/
protected function getUserImageUrl(array $response, AccessToken $token)
{
$image = $this->getUserImage($response, $token);

if (isset($image['image']['imageUrl'])) {
return $image['image']['imageUrl'];
}
Expand Down
5 changes: 3 additions & 2 deletions src/Provider/YahooUser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Hayageek\OAuth2\Client\Provider;

use League\OAuth2\Client\Provider\ResourceOwnerInterface;
Expand All @@ -9,7 +10,7 @@ class YahooUser implements ResourceOwnerInterface
* @var array
*/
protected $response;


/**
* @var image URL
Expand Down Expand Up @@ -40,7 +41,7 @@ public function getName()
nickname is not coming in the response.
$this->response['profile']['nickname']
*/
return $this->getFirstName()." ".$this->getLastName();
return $this->getFirstName() . " " . $this->getLastName();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ protected static function initAutoloader()
{
$vendorPath = static::findParentPath('vendor');

$loader = include $vendorPath.'/autoload.php';
$loader = include $vendorPath . '/autoload.php';
}

protected static function findParentPath($path)
{
$dir = __DIR__;
$previousDir = '.';
while (!is_dir($dir.'/'.$path)) {
while (!is_dir($dir . '/' . $path)) {
$dir = dirname($dir);
if ($previousDir === $dir) {
return false;
}
$previousDir = $dir;
}

return $dir.'/'.$path;
return $dir . '/' . $path;
}
}

Expand Down
Loading

0 comments on commit 57fb5b9

Please sign in to comment.