question

ryan3235484008 avatar image
ryan3235484008 asked Gaatu Support commented

PHP - No Token Found error when refreshing Oauth tokens.

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?

api authphp
1 comment
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I am having the same error 'Token not found' from last 3 days. I was working fine before. When trying to call oauth API with valid refresh token but access token has expired then it throws error. Please help.

0 Likes 0 ·
ryan3235484008 avatar image
ryan3235484008 answered

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 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Anirban avatar image
Anirban answered Anirban edited

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 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

ryan3235484008 avatar image
ryan3235484008 answered Phong Vu commented

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!

1 comment
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Just to let you know I got the same error and I am investigating this bug.

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered

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();
    }
}
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys