Closed leewillis77 closed 4 years ago
Yep, that's correct. Though having to call getAuthenticator()
twice there seems a bit silly, so the attached PR now has fetchAccessAndRefreshToken()
returning the authenticator.
Perfect - thanks. 👍
@bkuhl Is there any exception thrown when the access token expired and needs to refresh? How can we identify if the token expired?
Here's a snippet from https://developer.helpscout.com/mailbox-api/overview/authentication/#response-2
This token is valid for 2 hours and you should create a new one only after the existing token expires. Expiration will be indicated by the API responding with HTTP 401.
In this case you're looking for a GuzzleHttp\Exception\ClientException
though it would be easier to see a specific exception for this case so I've added that to our v3 milestone - https://github.com/helpscout/helpscout-api-php/issues/153.
@bkuhl: thanks! I just checked and it works without refreshing the access token, it is strange... The access token was requested 2 days ago and it is still working fine.
I use only the following endpoint:
$client = \HelpScout\Api\ApiClientFactory::createClient();
$client = $client->useClientCredentials(HS_APP_ID, HS_APP_SECRET);
$client->setAccessToken($accessToken['access_token']);
return $client->threads()
->list($id);
The current docs explain how you can use a refresh token to make an API request, but not how to use one to retrieve updated access tokens.
After a bit of experimentation I've landed on the following code, but not sure if that's ideal?