Skip to content

Manual refresh of tokens #27

@KadHamW

Description

@KadHamW

Hey again,

I am loving the package, I have been able to integrate it into my app quite well.
The only issue I am having is the 30-minute timeout of the tokens,
I am unsure whether the package is supposed to handle this seamlessly in the background, but if that is the case it is not quite working.
Instead, I am trying to create a scheduled command that will refresh my tokens.
It appears to successfully generate new tokens, but either it isn't saving it properly back to the conf or something else is going on.
I am using the DB for my cache and that is working fine with the token info being added as expected.
So far I have this in the command, although it has been through many iterations and might be flat out wrong:

public function handle()
    {
    Log::info('Xero Heartbeat command run');
    try {
        $credentials = app(OauthCredentialManager::class);
        $config = app(Configuration::class);
        $oldTok = $config->getAccessToken();
        $credentials->refresh();
        $config->setAccessToken($credentials->getAccessToken());
        $newTok = $config->getAccessToken();
        Log::info("Token old: " . $oldTok . ". Token new: " . $newTok);
    } catch (\throwable $e) {
        Log::info("An error occured: " . $e->getMessage());
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions