Closed tm1000 closed 3 years ago
I've spent a few hours trying to figure out how to do this and I keep running into dead ends. Firstly the cache is broken because in one place you have a _
prefix and the other you don't. I got past that and I run into the issue that if you set an refreshToken using setRefreshToken
then you go and call refreshAccessToken
the response from $this->provider->getAccessToken
removes the refreshToken you previously set, thus attempting to rerun refreshAccessToken
(which is done in the CRM Library if there is a random 401 from zoho) fails because getAccessToken
removed the refresh token which causes a RefreshTokenNotSet
to be thrown.
I think the over reliance on AccessTokenInterface
is hurting you here. You need to store the values of refreshToken and accessToken locally in ZohoClient class. Relying on AccessTokenInterface
is not going to work. This is evident when you have to do 'access_token' => 'TEMP'
There's also no reason to cache the refreshToken, unless I am missing something. You never call it back. It's just written as is to the cache.
I'm noticing that v4 makes a call to Zoho on the initial setRefreshToken before any calls are made to the library. There doesn't seem to be any way around this because
$this->token
is always empty when the class initializes (https://github.com/Weble/ZohoClient/blob/v4/src/OAuthClient.php#L450) (https://github.com/Weble/ZohoClient/blob/v4/src/OAuthClient.php#L464)In v3 the call to get the access token was not made until
getAccessToken()
was calledWe should setRefreshToken blindly here. Don't put it into cache until getAccessToken() is run. Then you can
refreshAccessToken
ingetAccessToken
as wellThe overall issue with this is just setting setRefreshToken makes a call out to Zoho even if I never actually reach that code (think of using this in a service provider in Laravel where I have to set the refreshToken in the singleton/bind)