From ad6023c3db9b02dcc9b2675577b8b9c3c867c48f Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 10 Jun 2022 13:54:00 +0000 Subject: [PATCH] fix unable to access token --- composer.lock | 12 ++-- src/Appwrite/Auth/OAuth2/Dailymotion.php | 77 +++++++++++++----------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/composer.lock b/composer.lock index f470d7f480..3140a59d2c 100644 --- a/composer.lock +++ b/composer.lock @@ -481,16 +481,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.4.3", + "version": "7.4.4", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "74a8602c6faec9ef74b7a9391ac82c5e65b1cdab" + "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/74a8602c6faec9ef74b7a9391ac82c5e65b1cdab", - "reference": "74a8602c6faec9ef74b7a9391ac82c5e65b1cdab", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e3ff079b22820c2029d4c2a87796b6a0b8716ad8", + "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8", "shasum": "" }, "require": { @@ -585,7 +585,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.4.3" + "source": "https://github.com/guzzle/guzzle/tree/7.4.4" }, "funding": [ { @@ -601,7 +601,7 @@ "type": "tidelift" } ], - "time": "2022-05-25T13:24:33+00:00" + "time": "2022-06-09T21:39:15+00:00" }, { "name": "guzzlehttp/promises", diff --git a/src/Appwrite/Auth/OAuth2/Dailymotion.php b/src/Appwrite/Auth/OAuth2/Dailymotion.php index 164df7b5b3..2c8d468e21 100644 --- a/src/Appwrite/Auth/OAuth2/Dailymotion.php +++ b/src/Appwrite/Auth/OAuth2/Dailymotion.php @@ -14,8 +14,8 @@ class Dailymotion extends OAuth2 */ private string $endpoint = 'https://api.dailymotion.com'; private string $authEndpoint = 'https://www.dailymotion.com/oauth/authorize'; - - /** + + /** * @var array */ protected array $scopes = [ @@ -36,17 +36,17 @@ class Dailymotion extends OAuth2 'username', 'verified' ]; - + /** * @var array */ protected array $user = []; - + /** * @var array */ protected array $tokens = []; - + /** * @return string */ @@ -55,19 +55,27 @@ class Dailymotion extends OAuth2 return 'dailymotion'; } + /** + * @return array + */ + public function getFields(): array + { + return $this->fields; + } + /** * @return string */ public function getLoginURL(): string { $url = $this->authEndpoint . '?' . - \http_build_query([ - 'response_type' => 'code', - 'client_id' => $this->appID, - 'state' => \json_encode($this->state), - 'redirect_uri' => $this->callback, - 'scope' => \implode(' ', $this->getScopes()) - ]); + \http_build_query([ + 'response_type' => 'code', + 'client_id' => $this->appID, + 'state' => \json_encode($this->state), + 'redirect_uri' => $this->callback, + 'scope' => \implode(' ', $this->getScopes()) + ]); return $url; } @@ -80,7 +88,7 @@ class Dailymotion extends OAuth2 protected function getTokens(string $code): array { if (empty($this->tokens)) { - $response = $this->request( + $this->tokens = \json_decode($this->request( 'POST', $this->endpoint . 'oauth/token', ["Content-Type: application/x-www-form-urlencoded"], @@ -89,27 +97,26 @@ class Dailymotion extends OAuth2 "client_id" => $this->appID, "client_secret" => $this->appSecret, "redirect_uri" => $this->callback, + "code" => $code, 'scope' => \implode(' ', $this->getScopes()) ]) - ); + ),true); - $output = []; - \parse_str($response, $output); - $this->tokens = $output; + } return $this->tokens; } - - + + /** * @param string $refreshToken * * @return array */ - public function refreshTokens(string $refreshToken):array + public function refreshTokens(string $refreshToken): array { - // TODO: Fire request to oauth API to generate access_token using refresh token + $this->tokens = \json_decode($this->request( 'POST', $this->endpoint . '/oauth/token', @@ -138,10 +145,10 @@ class Dailymotion extends OAuth2 public function getUserID(string $accessToken): string { $user = $this->getUser($accessToken); - - // TODO: Pick user ID from $user response + + $userId = $user['id'] ?? ''; - + return $userId; } @@ -153,10 +160,10 @@ class Dailymotion extends OAuth2 public function getUserEmail(string $accessToken): string { $user = $this->getUser($accessToken); - - // TODO: Pick user email from $user response + + $userEmail = $user['email'] ?? ''; - + return $userEmail; } @@ -188,14 +195,14 @@ class Dailymotion extends OAuth2 public function getUserName(string $accessToken): string { $user = $this->getUser($accessToken); - - // TODO: Pick username from $user response + + $username = $user['username'] ?? ''; - + return $username; } - - /** + + /** * @param string $accessToken * * @return array @@ -208,11 +215,13 @@ class Dailymotion extends OAuth2 $this->endpoint . '/user/me?', ['Authorization: Bearer ' . \urlencode($accessToken)], \http_build_query([ - 'fields' => \implode(',', $fields)]) + 'fields' => \implode(',', $this->getFields()) + ]) ); $this->user = \json_decode($user, true); + \var_dump($this->user); } return $this->user; } -} \ No newline at end of file +}