Only the command line should be able to get credentials from the cache
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2020-05-08 21:34:36 -04:00
parent 545c495869
commit cacf19781d
2 changed files with 24 additions and 7 deletions

View File

@ -139,8 +139,13 @@ final class Auth {
*/
public function getAuthToken(): ?string
{
return $this->segment->get('auth_token', NULL)
?? $this->cache->get(K::AUTH_TOKEN_CACHE_KEY, NULL);
if (PHP_SAPI === 'cli')
{
return $this->segment->get('auth_token', NULL)
?? $this->cache->get(K::AUTH_TOKEN_CACHE_KEY, NULL);
}
return $this->segment->get('auth_token', NULL);
}
/**
@ -151,8 +156,13 @@ final class Auth {
*/
private function getRefreshToken(): ?string
{
return $this->segment->get('refresh_token')
?? $this->cache->get(K::AUTH_TOKEN_REFRESH_CACHE_KEY, NULL);
if (PHP_SAPI === 'cli')
{
return $this->segment->get('refresh_token')
?? $this->cache->get(K::AUTH_TOKEN_REFRESH_CACHE_KEY, NULL);
}
return $this->segment->get('refresh_token');
}
/**

View File

@ -155,19 +155,26 @@ final class Model {
*/
public function reAuthenticate(string $token)
{
$response = $this->getResponse('POST', K::AUTH_URL, [
$response = $this->requestBuilder->getResponse('POST', K::AUTH_URL, [
'headers' => [
'accept' => NULL,
'Content-type' => 'application/x-www-form-urlencoded',
'Accept-encoding' => '*'
],
'form_params' => [
'grant_type' => 'refresh_token',
'refresh_token' => $token
]
]);
$data = Json::decode(wait($response->getBody()->buffer()));
if (array_key_exists('error', $data))
{
dump($data['error']);
dump($response);
die();
}
if (array_key_exists('access_token', $data))
{
return $data;