From 2ef0533bee9fc667e9c54dad356fb4f1aa1f5cf3 Mon Sep 17 00:00:00 2001 From: atehnix Date: Wed, 4 Oct 2017 16:49:21 +0300 Subject: [PATCH] Auth: ability to get an access token along with user data. --- src/Auth.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Auth.php b/src/Auth.php index bcf4cad..4daf761 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -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; @@ -133,7 +149,7 @@ public function getToken($code) throw self::toException($data); } - return isset($data['access_token']) ? $data['access_token'] : $data; + return $data; } /**