Skip to main content

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 'RingCentralSDKHttpApiException' 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): RingCentralSDKHttpClient->send(Object(GuzzleHttpPsr7Request)) #1 phar:///data/lib/ringcentral-php-master/ringcentral.phar/ringcentral/ringcentral-php/src/Platform/Platform.php(465): RingCentralSDKPlatformPlatform->sendRequest(Object(GuzzleHttpPsr7Request), Array) #2 phar:///data/lib/ringcentral-php-master/ringcentral.phar/ringcentral/ringcentral-php/src/Platform/Platform.php(252): RingCentralSDKPlatformPlatform->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?

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:

https://forums.developers.ringcentral.com/questions/1228/oau-213-token-not-found-when-refresh-token-has-not.html

Sometimes it happens if the token gets invalidated . Check the above links if that can help you


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!


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. :(


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)$_SESSIONO'tokens']);
    if (!$platform->loggedIn()) {
        header("Location: http://localhost:5000");
        exit();
    }
}

Reply