databasedotcom gem を使用しています。config/database.yml ファイルで Client_id、client_secret、ユーザー名、パスワードを指定するだけで、1 つのアカウントのデータを取得できます。しかし、ユーザーのログインに応じてデータを取得したい。セールスフォースでの最初のユーザーログインで、彼は自分のセールスフォースアカウントからデータを取得します。2 番目 3 番目と 4 番目も同様です。任意の提案をいただければ幸いです。
サンプルコードは以下の通りです:-
データベース.yml:-
ホスト: login.salesforce.com client_id: Salesforce からのコンシューマー キー
client_secret: Salesforce からのコンシューマ シークレット
ユーザー名: ユーザー名
パスワード: パスワード+セキュリティトークン
デバッグ: 真
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