I am currently developing who requesting a rest api from salesforce. I am successfully getting a refresh_token as a response of my authorization with php curl. I want to know if is there any way to check if my current refresh_token is still valid or not ? so that if my refresh_token is not valid i can programmatically request another valid refresh_token.


2 Answers 2


The only way I know of to validate a refresh token is to attempt to use it to get an access token - if the attempt fails, the refresh token is no good.

  • What makes the refresh_token not valid ? is that a normal behaviour of the rest_token ? Commented Mar 9, 2016 at 7:23
  • The user or an admin can revoke the refresh token; the admin can also set policy to control the refresh token's lifetime.
    – metadaddy
    Commented Mar 10, 2016 at 4:23
  • In my case. I admin and user didn't manually revoke the stored refresh_token. And also I set the refresh_token policy to Valid until revoked so it means no expiry right ? and i can use my stored token to retrieve data anytime i want? My issue is very similar to this post but i dont get the excact fixed for this problem.salesforce.stackexchange.com/questions/65590/… Commented Mar 10, 2016 at 5:25
  • In these circumstances then, yes, the refresh token should be valid indefinitely, but if you were writing an app, you would want to handle the case where it might have been revoked.
    – metadaddy
    Commented Mar 10, 2016 at 20:54
  • Here is my project . 2 wordpress plugin . first plugin called portal, this plugin is used only for communicating salesforce authorization via oauth2 and then saved the refresh_token to my database. The only can made authorization is the admin the user can't. And then the second plugin task is to process user data from worpdress to salesforce via refresh_token grant type. 1 example of that is user registration. The only solution I know to get over this issue is when the refresh_token expires I will let user to reauthorize for new refresh_token and it is really bad. Commented Mar 11, 2016 at 1:55

You can't get refresh token using api so you need to trick the code to validate session in following way.

try {

                /*************call getservicetimestamp to validate*******/ 
                $timstamp = $mySforceConnection->getServerTimestamp();

        } catch (Exception $e) {
                    /********Create connection again*********/


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .