Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RoR talking to Salesforce using OAuth

RoR talking to Salesforce using OAuth

How to connect your RoR app to Salesforce using restforce and omniauth-salesforce gems.

Bruno Fagundez

June 11, 2015
Tweet

More Decks by Bruno Fagundez

Other Decks in Programming

Transcript

  1. www.geekymartian.com @geekymartian
    RoR talking to Salesforce
    using OAuth
    +

    View full-size slide

  2. www.geekymartian.com @geekymartian
    Ruby

    View full-size slide

  3. www.geekymartian.com @geekymartian
    Ruby Gems

    View full-size slide

  4. www.geekymartian.com @geekymartian
    Ruby on Rails

    View full-size slide

  5. www.geekymartian.com @geekymartian
    =

    View full-size slide

  6. www.geekymartian.com @geekymartian
    OAuth

    View full-size slide

  7. www.geekymartian.com @geekymartian
    OAuth dance

    View full-size slide

  8. www.geekymartian.com @geekymartian

    View full-size slide

  9. www.geekymartian.com @geekymartian
    Connected App

    View full-size slide

  10. www.geekymartian.com @geekymartian
    Needed Gems
    restforce
    omniauth-salesforce

    View full-size slide

  11. www.geekymartian.com @geekymartian
    Rails User Model
    class User < ActiveRecord::Base
    def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid).permit!).first_or_initialize.tap do |user|
    user.provider = auth.provider
    user.uid = auth.uid
    user.name = auth.info.name
    user.oauth_token = auth.credentials.token
    user.refresh_token = auth.credentials.refresh_token
    user.instance_url = auth.credentials.instance_url
    user.save!
    end
    end
    end

    View full-size slide

  12. www.geekymartian.com @geekymartian
    client = Restforce.new :oauth_token => current_user.oauth_token,
    :refresh_token => current_user.refresh_token,
    :instance_url => current_user.instance_url,
    :client_id => 'YOUR-CONSUMER-KEY',
    :client_secret => 'YOUR-CONSUMER-SECRET'
    Restforce Interaction

    View full-size slide

  13. www.geekymartian.com @geekymartian
    http://www.geekymartian.com/articles/ruby-on-rails-4-
    salesforce-oauth-implementation/

    View full-size slide

  14. www.geekymartian.com @geekymartian
    Gracias!

    View full-size slide