简体   繁体   English

如何根据用户登录获取红宝石应用程序中的数据salesforce帐户?

[英]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.

相关问题 使用databasedotcom ruby​​ gem访问Salesforce时,如何获取特定用户(或帐户)的ActivityHistory - When using databasedotcom ruby gem to access salesforce, how do I get the ActivityHistory for a particular User (or Account) 如何使用Restforce gem在ruby on rails中获取与Salesforce客户对象的所有关联数据 - How to get all associated data with the salesforce account object in ruby on rails using restforce gem Ruby on Rails-继承-用户帐户 - Ruby on Rails - Inheritance - User Accounts 如何在Rails应用程序视图中的ruby中获取用户ID - How to get user id in ruby on rails app views 如何使用单独的用户帐户创建Rails应用程序? - How do I create a Rails app with separate user accounts? 如何从旧的(非红宝石)应用程序获取数据到新的(红宝石)应用程序? - How do I get data from an old (non-ruby) app to a new (ruby) app? 获取转发推文帐户的用户ID-红宝石 - Obtain user id of accounts retweeting a tweet - ruby Ruby on Rails api和客户端应用程序。 如何获取数据? - Ruby on Rails api and client app. How to get data? Ruby on Rails Web服务,用于移动应用程序的用户登录 - Ruby on Rails web service for user login for mobile app 在Rails上使用ruby构建shopify应用时,如何解决[GET]“ / login”路由错误? - How to solve the [GET] “/login” routing error while building shopify app using ruby on rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM