I feel like this should be really easy to do, but I can't find anything about it on the web. Is there a way, through either javascript or a java web servlet, to skip the subsequent authentication?

We are trying to use the REST Api in production, but the problem is, that each time you refresh the page in javascript, or delete the cookies in java, you have to login again to salesforce.

Is there some way to do an ajax call or the login in the background or whatever, so that you can have your application connecting to salesforce right away?


1 Answer 1


You can use Web Server or User Agent OAuth flows to achieve this. The first time you authenticate with Salesforce you can request a refresh token. You will have to make sure that your Connected App is setup to allow you to request the refresh_token scope.

Then in your subsequent requests, if your session has expired you can use this refresh token to request a new session without any input from the user.

Authentication is covered in quite some depth in the Force.com REST API Developer Guide.

  • I had no time yet testing this, when I come back to it and it comes out right, I will select it as the right answer :-) thank you for your help! Jun 5, 2015 at 15:33
  • 1
    Hey Alex, better late than never, I just went through my questions and realised I didn't accept this yet. Oct 23, 2017 at 14:42

You must log in to answer this question.

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