Skip to content

Commit

Permalink
VKontakte provider now returns the 'email' field
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored and m1guelpf committed Sep 22, 2018
1 parent cc738ae commit 109fed4
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Provider extends AbstractProvider implements ProviderInterface
/**
* Last API version.
*/
const VERSION = '5.78';
const VERSION = '5.85';

/**
* {@inheritdoc}
Expand All @@ -49,14 +49,20 @@ protected function getTokenUrl()
*/
protected function getUserByToken($token)
{
$from_token = [];
if (is_array($token)) {
$from_token["email"] = $token["email"];
$token = $token["access_token"];
}

$params = http_build_query([
'access_token' => $token,
'fields' => implode(',', $this->fields),
'language' => $this->getConfig('lang', 'en'),
'v' => self::VERSION,
]);

$response = $this->getHttpClient()->get('https://api.vk.com/method/users.get?'.$params);
$response = $this->getHttpClient()->get('https://api.vk.com/method/users.get?' . $params);

$contents = $response->getBody()->getContents();

Expand All @@ -69,7 +75,29 @@ protected function getUserByToken($token)
));
}

return $response['response'][0];
return array_merge($from_token, $response['response'][0]);
}

/**
* {@inheritdoc}
*/
public function user() {
if ($this->hasInvalidState()) {
throw new InvalidStateException();
}

$response = $this->getAccessTokenResponse($this->getCode());

$user = $this->mapUserToObject($this->getUserByToken($response));

$this->credentialsResponseBody = $response;

if ($user instanceof User) {
$user->setAccessTokenResponseBody($this->credentialsResponseBody);
}

return $user->setToken($this->parseAccessToken($response))
->setExpiresIn($this->parseExpiresIn($response));
}

/**
Expand Down

0 comments on commit 109fed4

Please sign in to comment.