1

I have an external application that has a bunch of information to create new Lead objects. As well I've created a RestResource Apex class that is mapped to URLs on the salesforce instance for my client's Org. This RestResource allows basic CRUD operations on the Lead object. The point I'm not clear on now is how to authenticate my server application using OAuth2 in order to call the urls for my RestResource class.

I was looking at the Connected Apps page in my Org and it looks like this is just for creating web flows for OAuth. How do I begin to authenticate programmatically to get an access token to hit the Resource URLs? Or is there something else I need to do? The hard requirement is that there won't be user intervention to authorize the server application.

1

For a headless process where there will be no user interaction you could use the OAuth 2.0 Username-Password Flow.

With this approach you would securely store the credentials on the server for an integration API user. Then using the grant_type password you can get an access token to work with you custom Rest APIs.

For an API integration user you don't want the password to be reset. Giving them a dedicated API user profile with the appropriate password policies is probably a good idea.


Alternatively, you could try storing the refresh token on the server and using the OAuth 2.0 refresh token flow. This has the benefit that you don't need to store a user name and password on the server. However, you will still need a user interaction to get the initial refresh token and another process to handle the refresh token being invalid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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