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
Danny_SDanny_S 

PHP toolkit modification for LoginScopeHeader

Hi,
 
I'm stuck , Can somone reffer me to what modification should be done to the PHP toolkit in order to set the LoginScopeHeader correctly ?
 
Thank you!
Danny.
 
vdevvdev
I need to authenticate self service users via API and I am using PHP toolkit, if anyone has updated to handle Loginscope header for that. Please let me know.
 
thanks
pgreggpgregg
Thanks to Kevin (see this thread:) http://community.salesforce.com/sforce/board/message?board.id=PerlDevelopment&message.id=2288#M2288

I got started with the necessary patch to use LoginScopeHeader.   Since SFDC implemented PortalIDs, I had to patch the code slightly more to cope with that - but now I have this working successfully authenticating a portal username and password via the API.

Here is a unified diff against the php-1.1.1 download:

diff -b -u -r php5-1.1.1/soapclient/SforceBaseClient.php php5-1.1.1_patched/soapclient/SforceBaseClient.php
--- php5-1.1.1/soapclient/SforceBaseClient.php  Thu Nov 29 14:11:23 2007
+++ php5-1.1.1_patched/soapclient/SforceBaseClient.php  Thu Nov 29 14:12:12 2007
@@ -100,9 +100,11 @@
    *
    * @return LoginResult
    */
-  public function login($username, $password) {
+  public function login($username, $password, $login_scope_header = NULL) {
     $this->sforce->__setSoapHeaders(NULL);
-    if (isset ($this->client_id)) {
+    if ($login_scope_header != NULL) {
+      $this->_setLoginScopeHeader($login_scope_header);
+    } elseif (isset ($this->client_id)) {
       $header_array = array ();
       $this->_setClientId($header_array);
       $this->sforce->__setSoapHeaders($header_array);
@@ -239,6 +241,26 @@

   }

+  private function _setLoginScopeHeader($header) {
+    // clear the headers first!
+    $this->sforce->__setSoapHeaders(NULL);
+
+    $login_scope_header = new SoapHeader($this->namespace, 'LoginScopeHeader', array (
+      'organizationId' => $header->organizationId,
+      'portalId' => $header->portalId
+    ));
+
+    $session_header = new SoapHeader($this->namespace, 'SessionHeader', array (
+      'sessionId' => $this->sessionId
+    ));
+    $header_array = array (
+      $session_header,
+      $login_scope_header
+    );
+    $this->_setClientId($header_array);
+    $this->sforce->__setSoapHeaders($header_array);
+  }
+
   public function getSessionId() {
     return $this->sessionId;
   }
diff -b -u -r php5-1.1.1/soapclient/SforceHeaderOptions.php php5-1.1.1_patched/soapclient/SforceHeaderOptions.php
--- php5-1.1.1/soapclient/SforceHeaderOptions.php       Thu Nov 29 14:11:23 2007
+++ php5-1.1.1_patched/soapclient/SforceHeaderOptions.php       Thu Nov 29 14:12:12 2007
@@ -26,7 +26,7 @@
  */

 /**
- * This file contains three classes.
+ * This file contains four classes.
  * @package SalesforceSoapClient
  */
 /**
@@ -89,4 +89,26 @@
     $this->batchSize = $limit;
   }
 }
+
+/**
+ * To be used with Login operation, but only to authenticate self-service users
+ *
+ * @package SalesforceSoapClient
+ */
+class LoginScopeHeader {
+  // string - organization Id of the salesforce customer against which we want to authenticate self-service users.
+  public $organizationId;
+  public $portalId;
+
+  /**
+   * Constructor
+   *
+   * @param string $orgId  organization Id
+   * @param string $portalId  portal Id
+   *    */
+  public function __construct($orgId, $portalId) {
+    $this->organizationId = $orgId;
+    $this->portalId = $portalId;
+  }
+}
 ?>


You then can login as portal users with the following code:
$login_scope_header = new LoginScopeHeader($orgId, $portalId);
$loginResult = $apiSforceConnection->login($portalusername, $portalpassword, $login_scope_header);

Regards,
PG