Open themightychris opened 5 years ago
Doesn't seem like this is maintained anymore but here is a command I made to run every hour to keep the token fresh
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use LifeOnScreen\LaravelQuickBooks\QuickBooksTokenHandlerInterface;
use QuickBooksOnline\API\DataService\DataService;
class RefreshQuickbooksToken extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'refresh-quickbooks-token';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Refresh quickbooks token';
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$tokenHandler = app(QuickBooksTokenHandlerInterface::class);
$oauthToken = DataService::Configure([
'auth_mode' => config('quickbooks.data-service.auth-mode'),
'ClientID' => config('quickbooks.data-service.client-id'),
'ClientSecret' => config('quickbooks.data-service.client-secret'),
'RedirectURI' => config('quickbooks.data-service.redirect-uri'),
'scope' => config('quickbooks.data-service.scope'),
'baseUrl' => config('quickbooks.data-service.base-url'),
'refreshTokenKey' => $tokenHandler->getRefreshToken(),
])->getOAuth2LoginHelper()->refreshToken();
$tokenHandler->setAccessToken($oauthToken->getAccessToken());
$tokenHandler->setRefreshToken($oauthToken->getRefreshToken());
}
}
Is any feature in the works already to handle refreshing expired access tokens via the refresh token automatically?