Based on the Quinton Wall's tutorial and utilizing Richard Vanhook's omniauth-salesforce, this is an update to this popular example running with Rails 3.1.3 with the following gems; oauth2 (0.5.2), omniauth (1.0.2), omniauth-oauth2 (1.0.0), omniauth-salesforce (1.0.3) and httparty (0.8.1). Thanks to Quinton and Richard for their great work on these projects. Here are some brief instructions on how to use it;
- Clone this repo to your development environment.
- Create .key and .crt files as per this article.
- Create the directory lib/certs and copy the .key and .crt files from the previous step to it.
- Configure WEBrick so it supports HTTPS using this article as a guide. Don't forget to modify the generic paths so they point to the .key and .crt files you created above.
- Create and then modify config/omniauth.yml as shown below so that it has your Salesforce key and secret, changing the placeholders to your actual key and secret.
- Make sure the Salesforce account to which these keys are related has REST enabled!
- Start WEBrick with
rails server
while in the root directory of your project. - Point browser to
https://localhost:3000
- Click 'auth/salesforce' link
- You should be redirected to Salesforce login page, to which you enter your credentials.
- Approve access by the application.
- When returned to the home page, you should now see the Auth token
- Click on the '/accounts' link.
- You should see the dump of the Account information.
To see Oauth refresh token in action:
- Login to Salesforce ... Navigate to 'Administration Setup > Security Controls > Session Settings
- Set session timeout to shortest (15 min.)
- Start / restart this demo app ... follow steps 8 - 14 above to get Account data.
- Wait longer than session timeout (15 min.).
- Refresh account page. You will get renewed display of account data.
- Look at server log ... see refresh token flow.
# simple omniauth.yml configuration file
key: <key>
secret: <secret>
Any questions comments, please don't hesitate to get in touch. The best way is likely to be Twitter @IntellogInc.