Expirty token into spotify
This commit is contained in:
parent
3303dd1f4b
commit
76c8da92a3
1 changed files with 52 additions and 15 deletions
|
@ -32,6 +32,11 @@ class Spotify extends OAuth2
|
||||||
*/
|
*/
|
||||||
protected $user = [];
|
protected $user = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $tokens = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -62,22 +67,54 @@ class Spotify extends OAuth2
|
||||||
*/
|
*/
|
||||||
public function getTokens(string $code): array
|
public function getTokens(string $code): array
|
||||||
{
|
{
|
||||||
$header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret);
|
if(empty($this->tokens)) {
|
||||||
$result = \json_decode($this->request(
|
$header = "Authorization: Basic " . \base64_encode($this->appID . ":" . $this->appSecret);
|
||||||
'POST',
|
$this->tokens = \json_decode($this->request(
|
||||||
$this->endpoint . 'api/token',
|
'POST',
|
||||||
[$header],
|
$this->endpoint . 'api/token',
|
||||||
\http_build_query([
|
[$header],
|
||||||
"code" => $code,
|
\http_build_query([
|
||||||
"grant_type" => "authorization_code",
|
"code" => $code,
|
||||||
"redirect_uri" => $this->callback
|
"grant_type" => "authorization_code",
|
||||||
])
|
"redirect_uri" => $this->callback
|
||||||
), true);
|
])
|
||||||
|
), true);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return $this->tokens;
|
||||||
'access' => $result['access_token'],
|
}
|
||||||
'refresh' => $result['refresh_token']
|
|
||||||
];
|
/**
|
||||||
|
* @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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue