1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00

Merge pull request #2750 from appwrite/fix-oauth-providers

Fix non-json responding OAuth providers
This commit is contained in:
Eldad A. Fux 2022-02-14 14:28:43 +02:00 committed by GitHub
commit ad010a5ae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View file

@ -65,7 +65,7 @@ class Bitly extends OAuth2
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
$response = $this->request(
'POST',
$this->resourceEndpoint . 'oauth/access_token',
["Content-Type: application/x-www-form-urlencoded"],
@ -76,7 +76,11 @@ class Bitly extends OAuth2
"redirect_uri" => $this->callback,
"state" => \json_encode($this->state)
])
), true);
);
$output = [];
\parse_str($response, $output);
$this->tokens = $output;
}
return $this->tokens;
@ -89,7 +93,7 @@ class Bitly extends OAuth2
*/
public function refreshTokens(string $refreshToken):array
{
$this->tokens = \json_decode($this->request(
$response = $this->request(
'POST',
$this->resourceEndpoint . 'oauth/access_token',
["Content-Type: application/x-www-form-urlencoded"],
@ -99,7 +103,11 @@ class Bitly extends OAuth2
"refresh_token" => $refreshToken,
'grant_type' => 'refresh_token'
])
), true);
);
$output = [];
\parse_str($response, $output);
$this->tokens = $output;
if(empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;

View file

@ -53,7 +53,7 @@ class Github extends OAuth2
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
$response = $this->request(
'POST',
'https://github.com/login/oauth/access_token',
[],
@ -63,7 +63,11 @@ class Github extends OAuth2
'client_secret' => $this->appSecret,
'code' => $code
])
), true);
);
$output = [];
\parse_str($response, $output);
$this->tokens = $output;
}
return $this->tokens;
@ -76,7 +80,7 @@ class Github extends OAuth2
*/
public function refreshTokens(string $refreshToken):array
{
$this->tokens = \json_decode($this->request(
$response = $this->request(
'POST',
'https://github.com/login/oauth/access_token',
[],
@ -86,7 +90,11 @@ class Github extends OAuth2
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken
])
), true);
);
$output = [];
\parse_str($response, $output);
$this->tokens = $output;
if(empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;