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

Refactored all providers, added expiry

This commit is contained in:
Matej Baco 2022-02-01 11:42:11 +01:00
parent 76c8da92a3
commit 89834af47d
31 changed files with 570 additions and 511 deletions

View file

@ -1168,6 +1168,17 @@ $collections = [
'array' => false,
'filters' => ['encrypt'],
],
[
'$id' => 'providerAccessTokenExpiry',
'type' => Database::VAR_INTEGER,
'format' => '',
'size' => 0,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'providerRefreshToken',
'type' => Database::VAR_STRING,

View file

@ -430,10 +430,10 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
}
$state['failure'] = null;
$tokens = $oauth2->getTokens($code);
$accessToken = $tokens['access'];
$refreshToken = $tokens['refresh'];
$accessToken = $oauth2->getAccessToken($code);
$refreshToken =$oauth2->getRefreshToken($code);
$accessTokenExpiry = $oauth2->getAccessTokenExpiry($code);
if (empty($accessToken)) {
if (!empty($state['failure'])) {
@ -533,6 +533,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
'providerUid' => $oauth2ID,
'providerAccessToken' => $accessToken,
'providerRefreshToken' => $refreshToken,
'providerAccessTokenExpiry' => $accessTokenExpiry,
'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak
'expire' => $expiry,
'userAgent' => $request->getUserAgent('UNKNOWN'),

View file

@ -109,6 +109,38 @@ abstract class OAuth2
return $this->scopes;
}
/**
* @param string $code
*
* @return string
*/
public function getAccessToken(string $code):string
{
$tokens = $this->getTokens($code);
return $tokens['access_token'];
}
/**
* @param string $code
*
* @return string
*/
public function getRefreshToken(string $code):string
{
$tokens = $this->getTokens($code);
return $tokens['refresh_token'];
}
/**
* @param string $code
*
* @return string
*/
public function getAccessTokenExpiry(string $code):string
{
$tokens = $this->getTokens($code);
return $tokens['expires_in'];
}
// The parseState function was designed specifically for Amazon OAuth2 Adapter to override.
// The response from Amazon is html encoded and hence it needs to be html_decoded before

View file

@ -16,6 +16,11 @@ class Amazon extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -63,26 +68,23 @@ class Amazon extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://api.amazon.com/auth/o2/token',
$headers,
\http_build_query([
'code' => $code,
'client_id' => $this->appID ,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'redirect_uri' => $this->callback ,
'redirect_uri' => $this->callback,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -15,6 +15,11 @@ class Apple extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -58,8 +63,9 @@ class Apple extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://appleid.apple.com/auth/token',
$headers,
@ -70,17 +76,13 @@ class Apple extends OAuth2
'client_secret' => $this->getAppSecret(),
'redirect_uri' => $this->callback,
])
);
), true);
$result = \json_decode($result, true);
$this->claims = (isset($result['id_token'])) ? \explode('.', $result['id_token']) : [0 => '', 1 => ''];
$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 [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -14,6 +14,11 @@ class Bitbucket extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -47,10 +52,10 @@ class Bitbucket extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
// Required as per Bitbucket Spec.
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://bitbucket.org/site/oauth2/access_token',
$headers,
@ -60,14 +65,10 @@ class Bitbucket extends OAuth2
'client_secret' => $this->appSecret,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -30,6 +30,11 @@ class Bitly extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @return string
*/
@ -58,7 +63,8 @@ class Bitly extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->resourceEndpoint . 'oauth/access_token',
["Content-Type: application/x-www-form-urlencoded"],
@ -69,14 +75,10 @@ class Bitly extends OAuth2
"redirect_uri" => $this->callback,
"state" => \json_encode($this->state)
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -24,6 +24,11 @@ class Box extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -63,11 +68,12 @@ class Box extends OAuth2
*/
public function getTokens(string $code): array
{
$header = "Content-Type: application/x-www-form-urlencoded";
$result = $this->request(
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . 'token',
[$header],
$headers,
\http_build_query([
"client_id" => $this->appID,
"client_secret" => $this->appSecret,
@ -76,14 +82,10 @@ class Box extends OAuth2
"scope" => \implode(',', $this->getScopes()),
"redirect_uri" => $this->callback
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -19,6 +19,11 @@ class Discord extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -59,7 +64,8 @@ class Discord extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . '/oauth2/token',
['Content-Type: application/x-www-form-urlencoded'],
@ -71,14 +77,10 @@ class Discord extends OAuth2
'client_secret' => $this->appSecret,
'scope' => \implode(' ', $this->getScopes())
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -15,6 +15,11 @@ class Dropbox extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -48,8 +53,9 @@ class Dropbox extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://api.dropboxapi.com/oauth2/token',
$headers,
@ -60,14 +66,10 @@ class Dropbox extends OAuth2
'redirect_uri' => $this->callback,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -16,6 +16,11 @@ class Facebook extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -51,22 +56,19 @@ class Facebook extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'GET',
'https://graph.facebook.com/'.$this->version.'/oauth/access_token?'.\http_build_query([
'https://graph.facebook.com/' . $this->version . '/oauth/access_token?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret,
'code' => $code
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -11,6 +11,11 @@ class Github extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -46,7 +51,8 @@ class Github extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://github.com/login/oauth/access_token',
[],
@ -56,14 +62,10 @@ class Github extends OAuth2
'client_secret' => $this->appSecret,
'code' => $code
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -14,6 +14,11 @@ class Gitlab extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -50,23 +55,20 @@ class Gitlab extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://gitlab.com/oauth/token?'.\http_build_query([
'https://gitlab.com/oauth/token?' . \http_build_query([
'code' => $code,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'redirect_uri' => $this->callback,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -30,6 +30,11 @@ class Google extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @return string
*/
@ -59,9 +64,10 @@ class Google extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://oauth2.googleapis.com/token?'.\http_build_query([
'https://oauth2.googleapis.com/token?' . \http_build_query([
'code' => $code,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
@ -69,14 +75,10 @@ class Google extends OAuth2
'scope' => null,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -11,6 +11,11 @@ class Linkedin extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -61,7 +66,8 @@ class Linkedin extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://www.linkedin.com/oauth/v2/accessToken',
['Content-Type: application/x-www-form-urlencoded'],
@ -72,14 +78,10 @@ class Linkedin extends OAuth2
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -15,6 +15,11 @@ class Microsoft extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -53,11 +58,11 @@ class Microsoft extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://login.microsoftonline.com/'.$this->getTenantId().'/oauth2/v2.0/token',
'https://login.microsoftonline.com/' . $this->getTenantId() . '/oauth2/v2.0/token',
$headers,
\http_build_query([
'code' => $code,
@ -67,14 +72,10 @@ class Microsoft extends OAuth2
'scope' => \implode(' ', $this->getScopes()),
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -23,6 +23,11 @@ class Mock extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @return string
*/
@ -51,23 +56,20 @@ class Mock extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'GET',
'http://localhost/'.$this->version.'/mock/tests/general/oauth2/token?'.
'http://localhost/' . $this->version . '/mock/tests/general/oauth2/token?' .
\http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret,
'code' => $code
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -21,6 +21,11 @@ class Notion extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -55,11 +60,9 @@ class Notion extends OAuth2
*/
public function getTokens(string $code): array
{
$headers = [
"Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
];
$result = $this->request(
if(empty($this->tokens)) {
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . '/oauth/token',
$headers,
@ -68,14 +71,10 @@ class Notion extends OAuth2
'redirect_uri' => $this->callback,
'code' => $code
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -35,6 +35,11 @@ class Paypal extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -78,7 +83,8 @@ class Paypal extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->resourceEndpoint[$this->environment] . 'oauth2/token',
['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)],
@ -86,14 +92,10 @@ class Paypal extends OAuth2
'code' => $code,
'grant_type' => 'authorization_code',
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -16,6 +16,11 @@ class Salesforce extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -63,28 +68,24 @@ class Salesforce extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = [
"Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
"Content-Type: application/x-www-form-urlencoded",
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
'Content-Type: application/x-www-form-urlencoded',
];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://login.salesforce.com/services/oauth2/token',
$headers,
\http_build_query([
'code' => $code,
'redirect_uri' => $this->callback ,
'redirect_uri' => $this->callback,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -11,6 +11,11 @@ class Slack extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -50,23 +55,20 @@ class Slack extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
// https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token
$result = $this->request(
$this->tokens = \json_decode($this->request(
'GET',
'https://slack.com/api/oauth.access?'.\http_build_query([
'https://slack.com/api/oauth.access?' . \http_build_query([
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'code' => $code,
'redirect_uri' => $this->callback
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -68,11 +68,11 @@ class Spotify extends OAuth2
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret);
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . 'api/token',
[$header],
$headers,
\http_build_query([
"code" => $code,
"grant_type" => "authorization_code",
@ -84,39 +84,6 @@ class Spotify extends OAuth2
return $this->tokens;
}
/**
* @param string $code
*
* @return string
*/
public function getAccessToken(string $code):string
{
$tokens = $this->getTokens($code);
return $tokens['access_token'];
}
/**
* @param string $code
*
* @return string
*/
public function getRefreshToken(string $code):string
{
$tokens = $this->getTokens($code);
return $tokens['refresh_token'];
}
/**
* @param string $code
*
* @return string
*/
public function getTokenExpiry(string $code):string
{
$tokens = $this->getTokens($code);
return $tokens['expires_in'];
}
/**
* @param $accessToken
*

View file

@ -11,6 +11,11 @@ class Stripe extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var string
*/
@ -61,7 +66,8 @@ class Stripe extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://connect.stripe.com/oauth/token',
[],
@ -69,18 +75,12 @@ class Stripe extends OAuth2
'grant_type' => $this->grantType['authorize'],
'code' => $code
])
);
), true);
$result = \json_decode($result, true);
if (isset($result['stripe_user_id'])) {
$this->stripeAccountId = $result['stripe_user_id'];
$this->stripeAccountId = $this->tokens['stripe_user_id'];
}
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -34,6 +34,11 @@ class Tradeshift extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected $scopes = [
'openid',
@ -73,7 +78,8 @@ class Tradeshift extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint[$this->environment] . 'auth/token',
['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)],
@ -81,14 +87,10 @@ class Tradeshift extends OAuth2
'grant_type' => 'authorization_code',
'code' => $code,
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -32,6 +32,11 @@ class Twitch extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @return string
*/
@ -63,9 +68,10 @@ class Twitch extends OAuth2
*/
public function getTokens(string $code): array
{
$result = \json_decode($this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . 'token?'. \http_build_query([
$this->endpoint . 'token?' . \http_build_query([
"client_id" => $this->appID,
"client_secret" => $this->appSecret,
"code" => $code,
@ -73,11 +79,9 @@ class Twitch extends OAuth2
"redirect_uri" => $this->callback
])
), true);
}
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -17,6 +17,11 @@ class Vk extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -61,8 +66,9 @@ class Vk extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://oauth.vk.com/access_token?',
$headers,
@ -72,21 +78,13 @@ class Vk extends OAuth2
'client_secret' => $this->appSecret,
'redirect_uri' => $this->callback
])
);
$result = \json_decode($result, true);
), true);
if (isset($result['email'])) {
$this->user['email'] = $result['email'];
$this->user['email'] = $this->tokens['email'];
$this->user['user_id'] = $this->tokens['user_id'];
}
if (isset($result['user_id'])) {
$this->user['user_id'] = $result['user_id'];
}
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -14,6 +14,11 @@ class WordPress extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -50,7 +55,8 @@ class WordPress extends OAuth2
*/
public function getTokens(string $code): array
{
$result = $this->request(
if(empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://public-api.wordpress.com/oauth2/token',
[],
@ -61,14 +67,10 @@ class WordPress extends OAuth2
'grant_type' => 'authorization_code',
'code' => $code
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -33,6 +33,11 @@ class Yahoo extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @return string
*/
@ -74,26 +79,25 @@ class Yahoo extends OAuth2
*/
public function getTokens(string $code): array
{
$header = [
"Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
"Content-Type: application/x-www-form-urlencoded",
if(empty($this->tokens)) {
$headers = [
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
'Content-Type: application/x-www-form-urlencoded',
];
$result = \json_decode($this->request(
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . 'get_token',
$header,
$headers,
\http_build_query([
"code" => $code,
"grant_type" => "authorization_code",
"redirect_uri" => $this->callback
])
), true);
}
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -19,6 +19,11 @@ class Yammer extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @return string
*/
@ -48,9 +53,9 @@ class Yammer extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . 'access_token?',
$headers,
@ -60,14 +65,10 @@ class Yammer extends OAuth2
'code' => $code,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -16,6 +16,11 @@ class Yandex extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @var array
*/
@ -60,12 +65,12 @@ class Yandex extends OAuth2
*/
public function getTokens(string $code): array
{
if(empty($this->tokens)) {
$headers = [
"Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret),
"Content-Type: application/x-www-form-urlencoded",
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
'Content-Type: application/x-www-form-urlencoded',
];
$result = $this->request(
$this->tokens = \json_decode($this->request(
'POST',
'https://oauth.yandex.com/token',
$headers,
@ -73,14 +78,10 @@ class Yandex extends OAuth2
'code' => $code,
'grant_type' => 'authorization_code'
])
);
), true);
}
$result = \json_decode($result, true);
return [
'access' => $result['access_token'],
'refresh' => $result['refresh_token']
];
return $this->tokens;
}
/**

View file

@ -46,6 +46,12 @@ class Session extends Model
'default' => '',
'example' => 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3',
])
->addRule('providerAccessTokenExpiry', [
'type' => self::TYPE_INTEGER,
'description' => 'Date, the user has accepted the invitation to join the team in Unix timestamp.',
'default' => 0,
'example' => 1592981250,
])
->addRule('providerRefreshToken', [
'type' => self::TYPE_STRING,
'description' => 'Session Provider Refresh Token.',