Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to use UserInfo endpoint #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 2 additions & 47 deletions src/Provider/Yahoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class Yahoo extends AbstractProvider
*/
protected $language = "en-us";

private $imageSize = '192x192';

public function getBaseAuthorizationUrl()
{
return 'https://api.login.yahoo.com/oauth2/request_auth';
Expand All @@ -33,30 +31,7 @@ public function getBaseAccessTokenUrl(array $params)

public function getResourceOwnerDetailsUrl(AccessToken $token)
{
$guid = $token->getResourceOwnerId();

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

/**
* Get user image from provider
*
* @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';

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

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

return $response;
return 'https://api.login.yahoo.com/openid/v1/userinfo';
}

protected function getAuthorizationParameters(array $options)
Expand Down Expand Up @@ -102,26 +77,6 @@ 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
*
* @return string
*/
protected function getUserImageUrl(array $response, AccessToken $token)
{
$image = $this->getUserImage($response, $token);

if (isset($image['image']['imageUrl'])) {
return $image['image']['imageUrl'];
}
return null;
return $user;
}
}
82 changes: 65 additions & 17 deletions src/Provider/YahooUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,47 @@ public function __construct(array $response)

public function getId()
{
return $this->response['profile']['guid'];
return $this->response['sub'];
}

/**
* Get perferred display name.
* Get preferred display name.
*
* @return string
*/
public function getName()
{
/*
nickname is not coming in the response.
$this->response['profile']['nickname']
*/
return $this->getFirstName() . " " . $this->getLastName();
return $this->response['name'];
}

/**
* Get perferred first name.
* Get preferred first name.
*
* @return string
* @return string|null
*/
public function getFirstName()
{
return $this->response['profile']['givenName'];
return $this->getResponseValue('given_name');
}

/**
* Get perferred last name.
* Get preferred last name.
*
* @return string
* @return string|null
*/
public function getLastName()
{
return $this->response['profile']['familyName'];
return $this->getResponseValue('family_name');
}

/**
* Get locale.
*
* @return string|null
*/
public function getLocale()
{
return $this->getResponseValue('locale');
}

/**
Expand All @@ -83,13 +89,47 @@ public function getEmail()
*/
public function getAvatar()
{
return $this->response['imageUrl'];
return $this->getResponseValue('picture');
}

/**
* Get nickname.
*
* @return string|null
*/
public function getNickname()
{
return $this->getResponseValue('nickname');
}

/**
* Get preferred username.
*
* @return string|null
*/
public function getPreferredUsername()
{
return $this->getResponseValue('preferred_username');
}

/**
* Get birth date.
*
* @return string|null
*/
public function getBirthYear()
{
return $this->getResponseValue('birthdate');
}

public function setImageURL($url)
/**
* Get phone number.
*
* @return string|null
*/
public function getPhone()
{
$this->response['imageUrl'] = $url;
return $this;
return $this->getResponseValue('phone_number');
}

/**
Expand All @@ -101,4 +141,12 @@ public function toArray()
{
return $this->response;
}

private function getResponseValue($key)
{
if (array_key_exists($key, $this->response)) {
return $this->response[$key];
}
return null;
}
}