function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jonc.ax191jonc.ax191 

Implementing single sign on for self service portal

I'm new to using the Sforce API and I was wondering if someone knows of an example of implementing single sign-on for the self service portal. For my scenario, a user logs into our software, navigates to the portal page on our site which automatically logs them in to the self-service portal, and then the portal is displayed in an Iframe on our site.

I suppose I can do a HTTP form post to "https://ssl.salesforce.com/sserv/login.jsp" to login the self-service user but can this be done through the API instead?

I use C#

Thanks,
Jon
jonc.ax191jonc.ax191
Nevermind -- I got it. I just used an HttpWebRequest to log them in and displayed the portal in an iframe. I also hid the logout tab behind a div to disable it.
surfoussurfous
Jon,

Can you share how you hid the logout tab behind a div? I assume you mean the one served by salesforce on the CSS portal pages?

Thanks,

--Kevin
RyanMRyanM
Jonc,

I am trying to use single sign on for our users to access self service after they login to our website. I was instructed to use the API and a SetPassword call. Do you have example code for this? Any help would be greatly appreciated.

-Ryan Moeller
(858) 726-1047
RyanMRyanM
Kevin,

I am trying to use single sign on for our users to access self service after they login to our website. I was instructed to use the API and a SetPassword call. Do you have example code for this? Any help would be greatly appreciated.

-Ryan Moeller
(858) 726-1047
jonc.ax191jonc.ax191
I wasn't able to implement auto-logon using the API. However when you first enable a user as a Self-Service Portal User, that's best done through the API. If someone knows how to implement auto-logon through the API, I'd like to hear it.

What I did to implement this was to do a post to the actual Self-Service Portal logon screen (the one's users would see), capture the reponse, yank out the redirection URL from the response, and immediately redirect the user with the URL. I use C#.

Here's an example (I didn't try to compile this). This method logs the user in and returns the redirection URL.

private string LoginToSalesforce()
{
string myOrgID = "1234567XXXX"; //Your company's ID
string myUsername = "janedone"; //The self-service user
string myPass = "boo";

string loginDataToPost = "orgId=" + myOrgID + "&un=" + myUsername + "&pw=" + myPass;

//encode data and convert to byte array to send
UTF8Encoding encoding = new UTF8Encoding();
byte[] byteArray = encoding.GetBytes(loginDataToPost);

//Create HttpWebRequest
HttpWebRequest reqSF = (HttpWebRequest) WebRequest.Create("https://ssl.salesforce.com/sserv/login.jsp");
reqSF.Method = "POST";
reqSF.ContentType = "application/x-www-form-urlencoded";
reqSF.ContentLength = loginDataToPost.Length;

//Post the data stream to Salesforce
Stream requestStream = reqSF.GetRequestStream();
requestStream.Write(byteArray, 0, byteArray.Length);
requestStream.Close();

//Get the response data stream from Salesforce
HttpWebResponse respSF = (HttpWebResponse) reqSF.GetResponse();
Stream responseStream = respSF.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
string respHTML = readStream.ReadToEnd();

//Extract URL from other response data. Doing a string search is not the most elegant solution.
//First make sure login was successful
if (respHTML.IndexOf("Invalid username or password.") {

//The URL line we're looking for comes back in the datastream as
//"URL=/sserv/frontdoor.jsp?csssid=xxxxxxxxxxxxxxx&je=0" quotes included

int posBeginURL = respHTML.IndexOf("URL=") + 4; //offset to remove URL=
int posEndURL = respHTML.IndexOf("\"", posBeginURL); //position of the last double quote showing the end of the URL
int lengthURL = posEndURL - posBeginURL;
return "https://ssl.salesforce.com" + respHTML.Substring(posBeginURL, lengthURL); //the full redirection URL
}
else //Login failed
{
return "http://www.mysite.com/myprettyerrorpage.htm";
}
jonc.ax191jonc.ax191
Sure. I hate that little logout tab b/c it causes huge problems with auto-login for Self-Service users -- you have to do a bunch of stuff in code to detect and handle the user accidentally logging themselves out. I wish it could be disabled. Anyway here's my solution. It's definitely a workaround hack and doesn't display perfectly across browsers (IE and Firefox differ by a pixel in how they display divs so this looks perfect in one browser and off by a pixel in the other). Opera also has a problem with this if you use an IFrame to show the portal on your site.

1) Go to you self-service portal settings
2) Edit the "Page Header" (make sure it is displayed in your site)
3) Click the "Show Header" box and "Show HTML" box on the edit page
4) Here's my code for the edit box. If you've changed your font sizes, color scheme, etc, you'll need to change this as appropriate to get the colors to match and to position the div perfectly.



5) Click save and you're done. Die logout button die!
jonc.ax191jonc.ax191
Ack it rendered the html. Here's the code again

>DIV style="LEFT: 386px; POSITION: relative; TOP: 46px" z-index="1"<
>IMG height=35 src="https://ssl.salesforce.com/sserv/img/tabBg_gray.gif" width=62<
>/DIV<
SkowronekSkowronek
I've implemented a similar scenario and have a questions regarding session timeout and synchonization.
 
Please see my post if you have time.
 
Thanks.