Closed stojankukrika closed 3 years ago
Try adding also the access Token to the client, even if expired. I think the client tried to authenticate again using a auth_code (which is the first step you do to take the refresh token in the first place) if it doesn't find an access token.
@Skullbock you thing to add this:
$oAuthClient->setAccessToken(setting('zohobooks.token'));
after this line:
$oAuthClient->setRefreshToken(setting('zohobooks.refresh_token'));
? I get the same error.
Yes. Can you show the full backtrace of the exception?
Sure. `[2021-07-22 10:32:01] local.ERROR: invalid_code {"userId":1,"exception":"[object] (League\OAuth2\Client\Provider\Exception\IdentityProviderException(code: 200): invalid_code at /home/vagrant/projects/akaunting/modules/ZohoBooks/vendor/asad/oauth2-zoho/src/Provider/Zoho.php:112) [stacktrace]
"} `
Are you sure the refresh token you're setting is correct, and with the correct permission for the client id you are using? Seems like the system is trying to create a new refresh token
Hm.. I think it is... but let you check it. I have one middleware that is called before every request related to Zoho:
public function handle($request, Closure $next)
{
$client = new OAuthClient(setting('zohobooks.client_id'), setting('zohobooks.client_secret'));
$client->setRefreshToken(setting('zohobooks.refresh_token'));
$client->offlineMode();
setting()->set('zohobooks.refresh_token', $client->refreshAccessToken());
setting()->save();
return $next($request);
}
which store every time new refresh token.
On the first step to Authenticate to Zoho I have this:
$client = new \Weble\ZohoClient\OAuthClient(setting('zohobooks.client_id'), setting('zohobooks.client_secret'), 'us', url('/zohobooks/auth'));
$client->offlineMode();
when back from Zoho I store info into the database:
setting()->set([
'zohobooks.refresh_token' => $client->getRefreshToken(),
'zohobooks.token' => $client->getAccessToken(),
]);
setting()->save();
You dont' need to store a new refresh token every time, the refresh token is always the same one. You need to store the refreshed access token
Bro, you are a rock!!! AWESOME!!! Finally get something :D Thank you a lot for your time! If I can help you in anything be free to contact me ;)
No worries, OAuth2 is hard 👍
Just use the library, and PR any improvement to code / docs you see (this library or any other one)
Hi, I have one issue with this package if someone can help me. Connection to Zoho Books works well I get also a refresh token (offline mode) which is awesome. But I have issues for example to get all invoices or count invoices. When I try to get total invoices I made this code:
$total = $this->getClient()->invoices->getTotal();
where getClient method is this one:
and get this error:
local.ERROR: invalid_code {"userId":1,"exception":"[object] (League\\OAuth2\\Client\\Provider\\Exception\\IdentityProviderException(code: 200): invalid_code at /home/vagrant/projects/akaunting/modules/ZohoBooks/vendor/asad/oauth2-zoho/src/Provider/Zoho.php:112)