Client could try to fetch new access token if the provided one is invalid and refresh token is correct (AuthenticationException)
scr4bble opened this issue · 3 comments
We are getting this error:
AuthenticationException: Invalid Credentials in ...vendor/helpscout/api/src/Http/Handlers/AuthenticationHandler.php:19
We are not 100% sure why it happens that tokens sometimes become invalid.
In any case - I think that client should try to fetch correct access token if it has refresh token present and valid.
- PHP version: PHP 7.4
- SDK version: 3.2.0 Help Scout API v2 Client
This is how Client is initialized:
$this->client = ApiClientFactory::createClient([], function (Authenticator $authenticator) {
// $authenticator contains the refreshed tokens
$this->saveTokensIntoDatabase(null, $authenticator->getTokens());
});
$this->client->useRefreshToken($app_id, $app_secret, $refresh_token);
$this->client->setAccessToken($this->access_token);
Current behavior
If there is wrong access token entered into the client, next method that is using API will fail with AuthenticationException: Invalid Credentials.
Expected behavior
Could the client instead try to fetch new access token using the provided refresh token? And then only fails with authentication error if also refresh token is invalid.
Steps to reproduce
- Use the code above for client initialization and enter incorrect access token but correct refresh token
..
Update. I just found out that in some cases the access token is indeed automatically fetched when invalid. But the mail-sending method still raises exception.
I might have found the problem in the code. I will just learn how to do the pull request here and I will try to post it :)
Please review and include into live branch as soon as you can.