Compare commits
No commits in common. "947e1358b52270ff36bf87f4b4c60e9e54bf892d" and "b87550fae793aadf79be54a8bcaf7e9e6361ba21" have entirely different histories.
947e1358b5
...
b87550fae7
@ -198,7 +198,7 @@ final class API
|
|||||||
|
|
||||||
$x = $this->execute('query',$parameters);
|
$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));
|
throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY));
|
||||||
|
|
||||||
return new Customer($x->QueryResponse);
|
return new Customer($x->QueryResponse);
|
||||||
@ -251,8 +251,8 @@ final class API
|
|||||||
|
|
||||||
$x = $this->execute('query',$parameters);
|
$x = $this->execute('query',$parameters);
|
||||||
|
|
||||||
if ((! $x->QueryResponse) || (! object_get($x->QueryResponse,'Invoice')) || (count($x->QueryResponse->Invoice) !== 1))
|
if ((! $x->QueryResponse) || (! $x->QueryResponse->Invoice) || (count($x->QueryResponse->Invoice) !== 1))
|
||||||
throw new InvalidQueryResultException(sprintf('%s:Query response malformed [%s]',self::LOGKEY,serialize($x)));
|
throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY));
|
||||||
|
|
||||||
return new Invoice($x->QueryResponse);
|
return new Invoice($x->QueryResponse);
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,10 @@
|
|||||||
namespace Intuit\Models;
|
namespace Intuit\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Laravel\Socialite\Facades\Socialite;
|
use Laravel\Socialite\Facades\Socialite;
|
||||||
|
|
||||||
class ProviderToken extends Model
|
class ProviderToken extends Model
|
||||||
{
|
{
|
||||||
private const LOGKEY = 'IPT';
|
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'access_token_expires_at' => 'datetime:Y-m-d H:i:s',
|
'access_token_expires_at' => 'datetime:Y-m-d H:i:s',
|
||||||
'refresh_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 */
|
/* ATTRIBUTES */
|
||||||
|
|
||||||
public function getAccessTokenAttribute(string $value): ?string
|
public function getAccessTokenAttribute($value): ?string
|
||||||
{
|
{
|
||||||
if (! $this->hasAccessTokenExpired())
|
if (! $this->hasAccessTokenExpired())
|
||||||
return $value;
|
return $value;
|
||||||
@ -32,16 +29,11 @@ class ProviderToken extends Model
|
|||||||
|
|
||||||
public function hasAccessTokenExpired(): bool
|
public function hasAccessTokenExpired(): bool
|
||||||
{
|
{
|
||||||
return $this
|
return $this->access_token_expires_at->isPast();
|
||||||
->access_token_expires_at
|
|
||||||
->isPast();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refreshToken(): bool
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,6 @@ use Carbon\Carbon;
|
|||||||
use GuzzleHttp\RequestOptions;
|
use GuzzleHttp\RequestOptions;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Laravel\Passport\Exceptions\InvalidAuthTokenException;
|
use Laravel\Passport\Exceptions\InvalidAuthTokenException;
|
||||||
use Laravel\Socialite\Two\InvalidStateException;
|
use Laravel\Socialite\Two\InvalidStateException;
|
||||||
use Laravel\Socialite\Two\ProviderInterface;
|
use Laravel\Socialite\Two\ProviderInterface;
|
||||||
@ -17,8 +16,6 @@ use App\Models\{ProviderOauth,ProviderToken};
|
|||||||
|
|
||||||
class IntuitProvider extends AbstractProvider implements ProviderInterface
|
class IntuitProvider extends AbstractProvider implements ProviderInterface
|
||||||
{
|
{
|
||||||
private const LOGKEY = 'SIP';
|
|
||||||
|
|
||||||
private const hosts = [
|
private const hosts = [
|
||||||
'authorise' => 'https://appcenter.intuit.com/connect/oauth2',
|
'authorise' => 'https://appcenter.intuit.com/connect/oauth2',
|
||||||
'tokenendpoint' => 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer',
|
'tokenendpoint' => 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer',
|
||||||
@ -107,16 +104,12 @@ 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(), [
|
||||||
|
RequestOptions::HEADERS => $this->getAuthorisationHeader($to->provider),
|
||||||
$response = $this
|
RequestOptions::FORM_PARAMS => $this->getRefreshTokenFields($to->refresh_token),
|
||||||
->getHttpClient()
|
]);
|
||||||
->post($this->getTokenUrl(),[
|
|
||||||
RequestOptions::HEADERS => $this->getAuthorisationHeader($to->provider),
|
|
||||||
RequestOptions::FORM_PARAMS => $this->getRefreshTokenFields($to->refresh_token),
|
|
||||||
]);
|
|
||||||
|
|
||||||
switch ($response->getStatusCode()) {
|
switch ($response->getStatusCode()) {
|
||||||
case '200':
|
case '200':
|
||||||
@ -132,11 +125,10 @@ class IntuitProvider extends AbstractProvider implements ProviderInterface
|
|||||||
if (($x=Arr::get($body,'refresh_token')) !== $to->refresh_token) {
|
if (($x=Arr::get($body,'refresh_token')) !== $to->refresh_token) {
|
||||||
$to->refresh_token = $x;
|
$to->refresh_token = $x;
|
||||||
$to->refresh_token_expires_at = Carbon::now()->addSeconds(Arr::get($body,'x_refresh_token_expires_in'));
|
$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:
|
default:
|
||||||
throw new InvalidAuthTokenException(sprintf('Invalid response [%d] refreshing token for [%s] (%s)',$response->getStatusCode(),$to->user->email,$response->getBody()));
|
throw new InvalidAuthTokenException(sprintf('Invalid response [%d] refreshing token for [%s] (%s)',$response->getStatusCode(),$to->user->email,$response->getBody()));
|
||||||
|
Loading…
Reference in New Issue
Block a user