Implemented refresh token for all providers
This commit is contained in:
parent
63f5f923b0
commit
8f58069b48
26 changed files with 301 additions and 27 deletions
|
@ -94,7 +94,18 @@ class Amazon extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://api.amazon.com/auth/o2/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,21 @@ class Apple extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://appleid.apple.com/auth/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->getAppSecret(),
|
||||
])
|
||||
), true);
|
||||
|
||||
$this->claims = (isset($this->tokens['id_token'])) ? \explode('.', $this->tokens['id_token']) : [0 => '', 1 => ''];
|
||||
$this->claims = (isset($this->claims[1])) ? \json_decode(\base64_decode($this->claims[1]), true) : [];
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,18 @@ class Bitbucket extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://bitbucket.org/site/oauth2/access_token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Auth\OAuth2;
|
||||
|
||||
use Appwrite\Auth\OAuth2;
|
||||
use Utopia\Exception;
|
||||
|
||||
// Reference Material
|
||||
// https://dev.bitly.com/v4_documentation.html
|
||||
|
@ -88,7 +89,17 @@ class Bitly extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->resourceEndpoint . 'oauth/access_token',
|
||||
["Content-Type: application/x-www-form-urlencoded"],
|
||||
\http_build_query([
|
||||
"client_id" => $this->appID,
|
||||
"client_secret" => $this->appSecret,
|
||||
"refresh_token" => $refreshToken,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,18 @@ class Box extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . 'token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
"client_id" => $this->appID,
|
||||
"client_secret" => $this->appSecret,
|
||||
"refresh_token" => $refreshToken,
|
||||
"grant_type" => "refresh_token",
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,17 @@ class Discord extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . '/oauth2/token',
|
||||
['Content-Type: application/x-www-form-urlencoded'],
|
||||
\http_build_query([
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,18 @@ class Dropbox extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://api.dropboxapi.com/oauth2/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Auth\OAuth2;
|
||||
|
||||
use Appwrite\Auth\OAuth2;
|
||||
use Utopia\Exception;
|
||||
|
||||
class Facebook extends OAuth2
|
||||
{
|
||||
|
@ -78,7 +79,16 @@ class Facebook extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'GET',
|
||||
'https://graph.facebook.com/' . $this->version . '/oauth/access_token?' . \http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'redirect_uri' => $this->callback,
|
||||
'client_secret' => $this->appSecret,
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Auth\OAuth2;
|
||||
|
||||
use Appwrite\Auth\OAuth2;
|
||||
use Utopia\Exception;
|
||||
|
||||
class Github extends OAuth2
|
||||
{
|
||||
|
@ -75,7 +76,17 @@ class Github extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://github.com/login/oauth/access_token',
|
||||
[],
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,15 @@ class Gitlab extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://gitlab.com/oauth/token?' . \http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,15 @@ class Google extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://oauth2.googleapis.com/token?' . \http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,18 @@ class Linkedin extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://www.linkedin.com/oauth/v2/accessToken',
|
||||
['Content-Type: application/x-www-form-urlencoded'],
|
||||
\http_build_query([
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
'redirect_uri' => $this->callback,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,18 @@ class Microsoft extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://login.microsoftonline.com/' . $this->getTenantId() . '/oauth2/v2.0/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->getClientSecret(),
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Auth\OAuth2;
|
||||
|
||||
use Appwrite\Auth\OAuth2;
|
||||
use Utopia\Exception;
|
||||
|
||||
class Mock extends OAuth2
|
||||
{
|
||||
|
@ -79,7 +80,16 @@ class Mock extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'GET',
|
||||
'http://localhost/' . $this->version . '/mock/tests/general/oauth2/token?' .
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,16 @@ class Notion extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . '/oauth/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,15 @@ class Paypal extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->resourceEndpoint[$this->environment] . 'oauth2/token',
|
||||
['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)],
|
||||
\http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'refresh_token',
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,19 @@ class Salesforce extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = [
|
||||
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://login.salesforce.com/services/oauth2/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Auth\OAuth2;
|
||||
|
||||
use Appwrite\Auth\OAuth2;
|
||||
use Utopia\Exception;
|
||||
|
||||
class Slack extends OAuth2
|
||||
{
|
||||
|
@ -78,7 +79,15 @@ class Slack extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'GET',
|
||||
'https://slack.com/api/oauth.access?' . \http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,16 @@ class Spotify extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . 'api/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
"refresh_token" => $refreshToken,
|
||||
"grant_type" => "refresh_token",
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Auth\OAuth2;
|
||||
|
||||
use Appwrite\Auth\OAuth2;
|
||||
use Utopia\Exception;
|
||||
|
||||
class Stripe extends OAuth2
|
||||
{
|
||||
|
@ -34,7 +35,7 @@ class Stripe extends OAuth2
|
|||
|
||||
protected $grantType = [
|
||||
'authorize' => 'authorization_code',
|
||||
'refresh' => 'refresh_token'
|
||||
'refresh' => 'refresh_token',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -90,8 +91,17 @@ class Stripe extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://connect.stripe.com/oauth/token',
|
||||
[],
|
||||
\http_build_query([
|
||||
'grant_type' => $this->grantType['refresh'],
|
||||
'refresh_token' => $refreshToken,
|
||||
])
|
||||
), true);
|
||||
|
||||
$this->stripeAccountId = $this->tokens['stripe_user_id'];
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,15 @@ class Tradeshift extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint[$this->environment] . 'auth/token',
|
||||
['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)],
|
||||
\http_build_query([
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Auth\OAuth2;
|
||||
|
||||
use Appwrite\Auth\OAuth2;
|
||||
use Utopia\Exception;
|
||||
|
||||
// Reference Material
|
||||
// https://vk.com/dev/first_guide
|
||||
|
@ -94,7 +95,21 @@ class Vk extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://oauth.vk.com/access_token?',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
$this->user['email'] = $this->tokens['email'];
|
||||
$this->user['user_id'] = $this->tokens['user_id'];
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,17 @@ class WordPress extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://public-api.wordpress.com/oauth2/token',
|
||||
[],
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,20 @@ class Yahoo extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = [
|
||||
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
];
|
||||
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . 'get_token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
"refresh_token" => $refreshToken,
|
||||
"grant_type" => "refresh_token",
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,18 @@ class Yammer extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = ['Content-Type: application/x-www-form-urlencoded'];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
$this->endpoint . 'access_token?',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'client_id' => $this->appID,
|
||||
'client_secret' => $this->appSecret,
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'refresh_token'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,19 @@ class Yandex extends OAuth2
|
|||
*/
|
||||
public function refreshTokens(string $refreshToken):array
|
||||
{
|
||||
// TODO: Implement (Twitch as example)
|
||||
$headers = [
|
||||
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
];
|
||||
$this->tokens = \json_decode($this->request(
|
||||
'POST',
|
||||
'https://oauth.yandex.com/token',
|
||||
$headers,
|
||||
\http_build_query([
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'authorization_code'
|
||||
])
|
||||
), true);
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue