Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Auth: ability to get an access token along with user data.
Browse files Browse the repository at this point in the history
  • Loading branch information
atehnix committed Oct 4, 2017
1 parent 2648ee6 commit 2ef0533
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ public function getUrl()
* @throws VkException
*/
public function getToken($code)
{
$data = $this->getUserData($code);

if (!isset($data['access_token'])) {
throw new VkException('The access token is not present in the API response.');
}

return $data['access_token'];
}

/**
* @param string $code
* @return array
* @throws VkException
*/
public function getUserData($code)
{
if (!$code) {
return null;
Expand All @@ -133,7 +149,7 @@ public function getToken($code)
throw self::toException($data);
}

return isset($data['access_token']) ? $data['access_token'] : $data;
return $data;
}

/**
Expand Down

0 comments on commit 2ef0533

Please sign in to comment.