From dea874e36e71521e57a6b32434669209539f0c19 Mon Sep 17 00:00:00 2001 From: wess Date: Fri, 8 Jul 2022 10:41:12 -0400 Subject: [PATCH] Adds retreiving user info for user name and email --- src/Appwrite/Auth/OAuth2/etsy.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/etsy.php b/src/Appwrite/Auth/OAuth2/etsy.php index 82b3ce2c78..7fe0267c20 100644 --- a/src/Appwrite/Auth/OAuth2/etsy.php +++ b/src/Appwrite/Auth/OAuth2/etsy.php @@ -148,13 +148,9 @@ class Notion extends OAuth2 */ public function getUserID(string $accessToken):string { - $response = $this->getUser($accessToken); + $components = explode('.', $accessToken); - if (isset($response['bot']['owner']['user']['id'])) { - return $response['bot']['owner']['user']['id']; - } - - return ''; + return $components[0]; } /** @@ -164,7 +160,7 @@ class Notion extends OAuth2 */ public function getUserEmail(string $accessToken):string { - return ''; + return $this->getUser($accessToken)['primary_email']; } /** @@ -174,7 +170,7 @@ class Notion extends OAuth2 */ public function getUserName(string $accessToken):string { - return ''; + return $this->getUser($accessToken)['login_name']; } /** @@ -184,6 +180,17 @@ class Notion extends OAuth2 */ protected function getUser(string $accessToken) { + if(!empty($this->user)) { return $this->user; + } + + $headers = ['Authorization: Bearer ' . $accessToken]; + + $this->user = \json_decode($this->request( + 'GET', + 'https://api.etsy.com/v3/application/users/' . $this->getUserID($accessToken), + ), true); + + return $this->user; } }