Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refreshing access token? #9

Open
themightychris opened this issue Jul 29, 2019 · 1 comment
Open

Refreshing access token? #9

themightychris opened this issue Jul 29, 2019 · 1 comment

Comments

@themightychris
Copy link

Is any feature in the works already to handle refreshing expired access tokens via the refresh token automatically?

@RDelorier
Copy link

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());
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants