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
GlennAtAppirioGlennAtAppirio 

Authenticating SSP Users

We struggled a bit to figure out how to programmatically authenticate Self-Service Portal (SSP) users, so I thought I'd share our findings, if it'll help someone else.

In our instance, the SFDC SSP sits behind a Jive KB.  Users provide their username/password to Jive, but Jive delegates authentication to the SFDC SSP, so we need Jive to call the SSP.  The API documentation talks generally about the login() method for authenticating Users, and provides a nice sample.  However, when it comes to authenticating SelfServiceUsers, the documentation has only this cryptic note (and no example):

To authenticate active Self-Service users, use the LoginScopeHeader to specify the Organization ID against which Self-Service users are authenticated. A Self-Service user must exist and be active before being authenticated (see SelfServiceUser).


(p. 141 of the Apex 9.0 API Guide)

If you're not already familiar with the notion of setting SOAP headers, this will be hard to figure out.  So, here is working sample code to authenticate a SelfServiceUser:

Code:
public static void authenticateSelfServiceUser(String userName, String pwd) {
  try {
    SoapBindingStub binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
    String sforceURI = new SforceServiceLocator().getServiceName().getNamespaceURI();
    String orgId = "12345abc";  // put your SFDC OrgId here
    LoginScopeHeader loginScopeHeader = new LoginScopeHeader();
    loginScopeHeader.setOrganizationId(orgId);
    binding.setHeader(sforceURI, "LoginScopeHeader", loginScopeHeader);
    LoginResult lr = binding.login(userName, pwd);
    System.out.println("User " + userName + " authenticated - session id is " + lr.getSessionId() + ", userid = " + lr.getUserId());
  } catch (Throwable e) {
    System.out.println("Error while authenticating SSU " + userName + ": " + e);
  }
}

Hope this helps someone.

Glenn

Message Edited by GlennAtAppirio on 03-12-2007 02:29 AM