Compare commits

..

No commits in common. "947e1358b52270ff36bf87f4b4c60e9e54bf892d" and "b87550fae793aadf79be54a8bcaf7e9e6361ba21" have entirely different histories.

3 changed files with 13 additions and 29 deletions

View File

@ -198,7 +198,7 @@ final class API
$x = $this->execute('query',$parameters);
if ((! $x->QueryResponse) || (! object_get($x->QueryResponse,'Customer')) || (count($x->QueryResponse->Customer) !== 1))
if ((! $x->QueryResponse) || (! $x->QueryResponse->Customer) || (count($x->QueryResponse->Customer) !== 1))
throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY));
return new Customer($x->QueryResponse);
@ -251,8 +251,8 @@ final class API
$x = $this->execute('query',$parameters);
if ((! $x->QueryResponse) || (! object_get($x->QueryResponse,'Invoice')) || (count($x->QueryResponse->Invoice) !== 1))
throw new InvalidQueryResultException(sprintf('%s:Query response malformed [%s]',self::LOGKEY,serialize($x)));
if ((! $x->QueryResponse) || (! $x->QueryResponse->Invoice) || (count($x->QueryResponse->Invoice) !== 1))
throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY));
return new Invoice($x->QueryResponse);
}

View File

@ -3,13 +3,10 @@
namespace Intuit\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Laravel\Socialite\Facades\Socialite;
class ProviderToken extends Model
{
private const LOGKEY = 'IPT';
protected $casts = [
'access_token_expires_at' => 'datetime:Y-m-d H:i:s',
'refresh_token_expires_at' => 'datetime:Y-m-d H:i:s',
@ -17,7 +14,7 @@ class ProviderToken extends Model
/* ATTRIBUTES */
public function getAccessTokenAttribute(string $value): ?string
public function getAccessTokenAttribute($value): ?string
{
if (! $this->hasAccessTokenExpired())
return $value;
@ -32,16 +29,11 @@ class ProviderToken extends Model
public function hasAccessTokenExpired(): bool
{
return $this
->access_token_expires_at
->isPast();
return $this->access_token_expires_at->isPast();
}
public function refreshToken(): bool
{
Log::debug(sprintf('%s:= Refreshing token for [%s]',self::LOGKEY,$this->provider->name));
return Socialite::with($this->provider->name)
->refreshToken($this);
return Socialite::with($this->provider->name)->refreshtoken($this);
}
}

View File

@ -6,7 +6,6 @@ use Carbon\Carbon;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Laravel\Passport\Exceptions\InvalidAuthTokenException;
use Laravel\Socialite\Two\InvalidStateException;
use Laravel\Socialite\Two\ProviderInterface;
@ -17,8 +16,6 @@ use App\Models\{ProviderOauth,ProviderToken};
class IntuitProvider extends AbstractProvider implements ProviderInterface
{
private const LOGKEY = 'SIP';
private const hosts = [
'authorise' => 'https://appcenter.intuit.com/connect/oauth2',
'tokenendpoint' => 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer',
@ -107,13 +104,9 @@ class IntuitProvider extends AbstractProvider implements ProviderInterface
];
}
public function refreshToken($to)
public function refreshtoken($to)
{
Log::debug(sprintf('%s:= Refreshing token for [%d]',self::LOGKEY,$to->id));
$response = $this
->getHttpClient()
->post($this->getTokenUrl(),[
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
RequestOptions::HEADERS => $this->getAuthorisationHeader($to->provider),
RequestOptions::FORM_PARAMS => $this->getRefreshTokenFields($to->refresh_token),
]);
@ -132,11 +125,10 @@ class IntuitProvider extends AbstractProvider implements ProviderInterface
if (($x=Arr::get($body,'refresh_token')) !== $to->refresh_token) {
$to->refresh_token = $x;
$to->refresh_token_expires_at = Carbon::now()->addSeconds(Arr::get($body,'x_refresh_token_expires_in'));
Log::debug(sprintf('%s:= Refresh token updated.',self::LOGKEY));
}
$to->save();
return $to->save();
return TRUE;
default:
throw new InvalidAuthTokenException(sprintf('Invalid response [%d] refreshing token for [%s] (%s)',$response->getStatusCode(),$to->user->email,$response->getBody()));