[SalesForce] Salesforce REST API authentication

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?

Best Answer

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.

Related Topic