[英]how to get data salesforce accounts in ruby app according to user login?
I am using databasedotcom gem. 我正在使用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. 我只能通过在config / database.yml文件中指定Client_id,client_secret,用户名和密码来获取1个帐户的数据。 but i want to get data according to user login. 但是我想根据用户登录获取数据。 1st user login with salesforce he will get data from his salesforce account. 第一个用户使用salesforce登录后,他将从其salesforce帐户中获取数据。 same for 2nd 3rd and 4th. 第二,第三和第四相同。 Any suggestion will be appreciated. 任何建议将不胜感激。
Example code is below:- 示例代码如下:-
database.yml:- database.yml:-
host: login.salesforce.com client_id: the Consumer Key from Salesforce 主机:login.salesforce.com client_id:Salesforce的使用者密钥
client_secret: the Consumer Secret from Salesforce client_secret:Salesforce的消费者秘密
username: username 用户名:
password: password+securitytoken 密码:密码+安全令牌
debugging: true 调试:正确
sfdc_controller:- 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
I found an another gem omniauth-salescforce and it worked well for me. 我找到了另一个omniauth-salescforce宝石,对我来说效果很好。 I found very good guide from here:- http://geekymartian.com/articles/ruby-on-rails-4-salesforce-oauth-implementation/ 我从这里找到了很好的指南: -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 我从这里找到了示例代码示例: -https : //github.com/takahiro-yonei/OmniAuth-Salesforce-Sample
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.