如何根据用户登录获取 ruby 应用程序中的数据销售人员帐户?
how to get data salesforce accounts in ruby app according to user login?
我正在使用 databasedotcom gem。我只能通过在 config/database.yml 文件中指定 Client_id、client_secret、用户名和密码来获取 1 个帐户的数据。但我想根据用户登录获取数据。第一个用户使用 salesforce 登录,他将从他的 salesforce 帐户获取数据。第二个第三个和第四个也一样。
任何建议将不胜感激。
示例代码如下:-
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
我找到了另一个 gem omniauth-salescforce,它对我来说效果很好。
我从这里找到了很好的指南:-
http://geekymartian.com/articles/ruby-on-rails-4-salesforce-oauth-implementation/
我从这里找到了示例代码示例:-
https://github.com/takahiro-yonei/OmniAuth-Salesforce-Sample
我正在使用 databasedotcom gem。我只能通过在 config/database.yml 文件中指定 Client_id、client_secret、用户名和密码来获取 1 个帐户的数据。但我想根据用户登录获取数据。第一个用户使用 salesforce 登录,他将从他的 salesforce 帐户获取数据。第二个第三个和第四个也一样。 任何建议将不胜感激。
示例代码如下:-
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
我找到了另一个 gem omniauth-salescforce,它对我来说效果很好。 我从这里找到了很好的指南:- http://geekymartian.com/articles/ruby-on-rails-4-salesforce-oauth-implementation/
我从这里找到了示例代码示例:- https://github.com/takahiro-yonei/OmniAuth-Salesforce-Sample