Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

If I want my application to process jobs and send API REST requests to my APEX endpoints, which OAuth2 authorization/grant method should I use?

  • If I use authorization_code, then the browser needs to redirect (to Salesforce login page) and the user needs to confirm access. (This would be wrong right?).

I think that I would want to use grant_type : password

If I use password, then I can just set my organizations administration username and password in my application and use that.

I plan on batching up some requests and sending through gearman as a background process.

share|improve this question
add comment

1 Answer 1

I solved with this approach:

  1. use grant_type = authorization_code the first time and ACCESS_TYPE=offline.
  2. save the AccesToken and the RefreshToken in a custom setting.
  3. Start the background job and everytime the job starts, ask for a new token using the refresh token and grant_type = refresh_token.

You have all the documentation in google to do this. https://developers.google.com/accounts/docs/OAuth2WebServer?hl=es Look for "Using a refresh token"

share|improve this answer
    
If you save the token, do you also save the instance URL that you should be using to send your REST requests? –  Layke Feb 25 at 11:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.