I am writing a PHP application using the Official PHP SDK and the Oauth authorization flow.
When I have both a valid access token and a valid refresh token, I am able to call the PHP SDK's platform->refresh() function and renew both the access and refresh token. This gives me a new Access token and Refresh token, which expire in 1 hour and 1 week respectively.
However, if I attempt to refresh() the tokens when the Access token is expired, I get the following exception:
Next exception 'RingCentral\SDK\Http\ApiException' with message 'Token not found' in phar:///data/lib/ringcentral-php-master/ringcentral.phar/ringcentral/ringcentral-php/src/Http/Client.php:52 Stack trace: #0 phar:///data/lib/ringcentral-php-master/ringcentral.phar/ringcentral/ringcentral-php/src/Platform/Platform.php(329): RingCentral\SDK\Http\Client->send(Object(GuzzleHttp\Psr7\Request)) #1 phar:///data/lib/ringcentral-php-master/ringcentral.phar/ringcentral/ringcentral-php/src/Platform/Platform.php(465): RingCentral\SDK\Platform\Platform->sendRequest(Object(GuzzleHttp\Psr7\Request), Array) #2 phar:///data/lib/ringcentral-php-master/ringcentral.phar/ringcentral/ringcentral-php/src/Platform/Platform.php(252): RingCentral\SDK\Platform\Platform->requestToken('/restapi/oauth/...', Array)
I'm not sure why it gives an error saying "Token Not Found", when the refresh token continues to be valid and works for refreshing if the Access Token is valid. Why would I need a valid access token in order to get a new valid access token?
I'm quite confused. Any ideas?
You did not share your code where you call the $platform->login(...) and show how you keep the token info. But please follow this tutorial to save the token data in your session, then every time you call an API, set the token data. Here is the highlighted part
$platform->login(...); // save token data to session $_SESSION['tokens'] = $platform->auth()->data(); // set token data before using the $platform to call APIs if (isset($_SESSION['tokens'])){ $platform->auth()->setData((array)$_SESSION['tokens']); if (!$platform->loggedIn()) { header("Location: http://localhost:5000"); exit(); } }
Since you did not share any code, I don't know how you implement the login part and where do you save the token information. Based on the exception you posted, I can only suspect that the token info is missing w/o knowing the reason why.
So, either share the code where you implement/save the tokens (remember to delete sensitive info such as the client Id, client Secret etc.) and where you keep the platform instance or the token info so I can have a look at it.
You can also double check by print out the token $platform->auth()->data() before you refresh the token to see if the token info exists.
Alternatively, you can follow this quick start to see how to save the token info in a session and use it every time you call an API.
As of this morning, with no changes in code or calls, I'm now able to use only the refresh token to fetch a new access token.
It's entirely possible I did something stupid, and fixed it inadvertently while working on other things. I did encounter the issue late in my work yesterday, so I'm unfortunately unable to identify what changes I made, if any, that would fix it. This will sadly remain a mystery lost to time. :(
1. Yes, the access token is expired. That's the whole point - I'm trying to use the refresh token to get a new one!
2. No user credentials have been modified in the planck's time between when the access token was not expired and when it was expired.
3. The refresh token is not corrupted, as it works until the instant the Access Token expires. Unless, for some reason, 1 hour passing changes my stored refresh token, or changes how it's loaded into the platform (I checked, the _auth has the correct data), I highly doubt that this is the case.
I looked through your links (and I appreciate you doing a search and linking some stuff!), but nothing's relevant for me. The first one is a ruby installation using password flow, the second one was an issue where a user had more than 5 valid tokens and stopped being able to generate more valid tokens. My installation is expiring and refreshing the same refresh and access token, so there is only ever 1 valid token of each type at a time.
Ty tho!
Check this once:
https://forums.developers.ringcentral.com/questions/1221/tokeninvalid-oau-213-token-not-found.html
As per the above link:
This issue happens for a couple of reasons:
1. Access token might be expired or another access token would be generated before the current token is expired
2. when the credentials of the user might have changed while the access token would have been still valid
3. The token would have been corrupted
You can also check the below link:
Sometimes it happens if the token gets invalidated . Check the above links if that can help you
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder