You need to sign in to do that
Don't have an account?

Single-Sign-On from salesforce to Rails App using ASF
Using Activesalesforce and a Rails application, is there a way to specify that Activesalesforce use the Session ID and Server URL handed through from a custom link or S-Control?
I am looking for a seamless authentication transition from salesforce to my custom app as described in:
The only documentation I have found on establishing an ASF connection is to hard code the username and password in the database.yaml file of a Rails app.
Thanks in advance,
John
Michael,
I was never able to get the automatic authentication to work using the before_filter method. I used the manual connection method outlined mentioned bby Doug three post pror.
- or you can manage this entirely on your own using:
All Answers
$client->createConnection($wsdl);
$client->sessionId = $_GET['sessionId'];
$client->setSessionHeader($client->sessionId);
$client->setEndpoint($_GET['location']);
ASF has full session id authentication support. The database.yaml approach is only the begining and particularly useful for most Rails apps (salesforce backend or otherwise). There are a couple of approaches to SID auth:
- you can add the following to your app's /controllers/application.rb:
You need to insure that your custom link, scontrol, button, etc uses the query param names sid and api_server_url.
https://yoursite.com?sid={!API.Session_ID}&api_server_url={!API.Partner_Server_URL_80}
- or you can manage this entirely on your own using:
and retrieve the sid and server url using you own mechanism.
Message Edited by Doug Chasman on 01-30-2007 07:39 AM
Doug,
Thank you for your reply, it was very helpful and fast! I do have two follow questions about ASF if you have time.
Thank you,
John
Doug,
Using before_filter :asf_sid_authenticate in my application.rb file gives me the following error:
undefined method `asf_sid_authenticate' for #<class_name>
Looking at the code in sid_authentication_filter.rb it looks like I need to use
before_filter ActiveSalesforce::SessionIDAuthenticationFilter
Doing that gets me further allong but it also appears that each class that wants to use SID authentication needs to register for it. I get Incorrect username / password [] errors now as it is not establishing the connection in sid_authentication_filter.rb.
What am I missing? :smileysad:
Thanks,
John
Were you able to figure out to do Session Authentication (sid) with ActiveSalesforce? I'm at the same spot you mention in your post. I've added the before_filter to my application's controller and am passing the Session ID and Server URL in the query string.
Getting Incorrect username/password []
Help?
Thanks!
Michael
Michael,
I was never able to get the automatic authentication to work using the before_filter method. I used the manual connection method outlined mentioned bby Doug three post pror.
- or you can manage this entirely on your own using:
Is there is any way to merge Lead Id with URL on web tab?
as i created custom web tab and opening a lead activity report at my end.
what i need that when ever any lead is selected on sales force.
so i should know the Lead Id(which lead is selected) and on the basis of selected lead i can show the report running at my local server.
it's very urgent...
Thanks in advance,
Manas
I found this information really useful. Thanks to everyone contributing to ActiveSalesforce.
For anyone else trying this and struggling, here is the prototype code I ended up with in the controller handling my authentication. In my case I wanted to make sure that I could have users authenticate automatically when one of my pages was embedded in a standard Salesforce page (in an iframe), by passing the sessionid and serverurl as described in the previous posts, or they could authenticate through my standard login page.
To make sure I didn't hit Salesforce for every page request, while still handling changes to the Salesforce session id (through a logout or a session id timeout), I stored the salesforce session id in my own session, to allow a comparison to be made against the session id the page was passed, therefore allowing me to reauthenticate against Salesforce if necessary.
Anyway, this is my poorly tested (at least 5 minutes) code. The stuff about the abstract class I borrowed from somewhere else (wish I could credit the author, sorry), but it lets me keep my standard DB connection for my app, and have Salesforce just connect for a single class. It seems to work ok so far.
class ApplicationController < ActionController::Base
before_filter :set_user
protected
def set_user
# Check if the page comes inside salesforce (the first param is sfdc), or standalone.
#If inside salesforce, only authenticate if the current Ruby user session does not exist, or if the Salesforce session has changed (or is new)
set_user_sfdc if params[:remote_systemtype]=="sfdc" && (!session[:usernumber] || session[:sfdc_sessionid]!=params[:remote_sessionid])
#Handle a standard (non Salesforce) authentication, if necessary
@user = UserProfile.find(session[:usernumber]) if @user.nil? && session[:usernumber]
end
def set_user_sfdc
#Only do this if absolutely necessary - no Salesforce connection or Ruby user
if (SalesforceStructure.connection.nil? || @user.nil?)
#Connect with the information passed into the page
SalesforceStructure.establish_connection(:adapter => 'activesalesforce', :sid => params[:remote_sessionid], :url => params[:remote_serverurl])
binding = SalesforceStructure.connection.binding
#Use the API to get the current user session info
user_info = binding.getUserInfo([]).getUserInfoResponse.result
# Now lookup the user by their Salesforce 18 character user ID, in the Ruby database
@user = UserProfile.find_by_sfdc_userid(user_info.userId)
# If it doesn't exist, we're going to tell the user somehow that they need to talk to their sysadmin
if @user.nil?
flash[:error] = "This Salesforce.com user ID is not recognized by Consected. Please contact your systems administrator for access (quoting Salesforce user ID:" + user_info.userId + "), or login with your Consected username directly."
end
# Store my standard userid in my Ruby session
session[:usernumber]= @user.id
# Store my salesforce session id in my ruby session
session[:sfdc_sessionid]= params[:remote_sessionid]
end
end
end
class SalesforceStructure < SalesforceBase
# The main functions for my Salesforce integration
def blah
end
end
class SalesforceBase < ActiveRecord::Base
self.abstract_class = true
end
Good luck!