3

I need to be able to impersonate another user from my Trigger, and thinking that I could create a class that logins as another user using the REST API and then post messages from that class.

How would I go about doing that?

  • At a minimum you will need to switch out to a future context to call the REST API as a Trigger cannot directly make callouts. Can I ask why you need to impersonate another user? – Daniel Ballinger Nov 10 '14 at 21:15
  • @DanielBallinger so I can post a message to a Contact as another user under certain conditions. Otherwise, it will always post as the logged in user. – user5428 Nov 10 '14 at 23:25
3

You can do this using the JWT Bearer Token flow. Basically you register an OAuth app and authorize that app for the users you wish to impersonate. Now your future method will create a JWT Bearer Token containing the target user's username and exchange that for an access token with which you can call the REST API.

There is code to do this linked from this answer.

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.