Add command to refresh token

This commit is contained in:
Deon George 2024-08-23 15:41:53 +10:00
parent 6741d95073
commit e8b049a2e8
2 changed files with 56 additions and 1 deletions

View File

@ -0,0 +1,54 @@
<?php
namespace Intuit\Commands;
use Illuminate\Console\Command;
use Intuit\Traits\ProviderTokenTrait;
/**
* Refresh the Intuit tokens
*/
class TokenRefresh extends Command
{
use ProviderTokenTrait;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'intuit:token:refresh'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Refresh an access token';
/**
* Execute the console command.
*
* @return int
* @throws \Intuit\Exceptions\NotTokenException
*/
public function handle()
{
$to = $this->providerToken($this->argument('user'));
$old = $to->refresh_token;
$x = $to->refreshToken();
dump([
'access'=>$to->access_token,
'old'=>$old,
'refresh'=>$to->refresh_token,
'expires'=>(string)$to->refresh_token_expires_at,
'x'=>$x,
]);
return self::SUCCESS;
}
}

View File

@ -4,7 +4,7 @@ namespace Intuit\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use Intuit\Commands\{AccountGet,InvoiceGet,PaymentGet,TaxCodeGet};
use Intuit\Commands\{AccountGet,InvoiceGet,PaymentGet,TaxCodeGet,TokenRefresh};
/**
* Class IntuitServiceProvider.
@ -27,6 +27,7 @@ class IntuitServiceProvider extends ServiceProvider
InvoiceGet::class,
PaymentGet::class,
TaxCodeGet::class,
TokenRefresh::class,
]);
}