1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00

Expirty token into spotify

This commit is contained in:
Matej Baco 2022-02-01 09:22:55 +01:00
parent 3303dd1f4b
commit 76c8da92a3

View file

@ -32,6 +32,11 @@ class Spotify extends OAuth2
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
/**
* @return string
*/
@ -62,22 +67,54 @@ class Spotify extends OAuth2
*/
public function getTokens(string $code): array
{
$header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret);
$result = \json_decode($this->request(
'POST',
$this->endpoint . 'api/token',
[$header],
\http_build_query([
"code" => $code,
"grant_type" => "authorization_code",
"redirect_uri" => $this->callback
])
), true);
if(empty($this->tokens)) {
$header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret);
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . 'api/token',
[$header],
\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;
}
/**
* @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'];
}
/**