0
votes

I am using databasedotcom gem. I am able to get data for 1 account only by specifying Client_id, client_secret, username and password in config/database.yml file. but i want to get data according to user login. 1st user login with salesforce he will get data from his salesforce account. same for 2nd 3rd and 4th. Any suggestion will be appreciated.

Example code is below:-

database.yml:-

host: login.salesforce.com client_id: the Consumer Key from Salesforce

client_secret: the Consumer Secret from Salesforce

username: username

password: password+securitytoken

debugging: true

sfdc_controller:-

class Api::V1::SfdcsController < ApplicationController
include Databasedotcom::Rails::Controller
def getSfdcauthentication
username = params[:username]
password = params[:password]
client_id = params[:client_id]
client_secret = params[:client_secret]

client = Databasedotcom::Client.new :client_id => client_id, :client_secret => client_secret
begin
  oauth_token = client.authenticate :username => username, :password => password  #=> "the-oauth-token"
rescue =>e
  oauth_token = false
end

if oauth_token
  contact_class = client.materialize("Contact")
  @sf_contacts = Contact.all
respond_with(@sf_contacts) do |format|
  format.json { render :json => @sf_contacts.as_json }
end
else
  render json: {status:200,message:"Authentication failed"}
end
end
end
1
Please, provide some code.Timothée Bourguignon
Please, check the example @TimBourguignonDipam Shrivastav
In what way is it not working?superfell
I wanted the data as per users.. but i was getting the data for only one account which i has specified in database.yml. but now i have fixed the problem by using another gem called omniauth-salesforce.Dipam Shrivastav

1 Answers

1
votes

I found an another gem omniauth-salescforce and it worked well for me. I found very good guide from here:- http://geekymartian.com/articles/ruby-on-rails-4-salesforce-oauth-implementation/

and I found the sample code example from here :- https://github.com/takahiro-yonei/OmniAuth-Salesforce-Sample