You are here

function soap_transport_http::setCredentials in Salesforce Suite 5

Same name in this branch
  1. 5 includes/nusoap.php \soap_transport_http::setCredentials()
  2. 5 includes/nusoap.orig.php \soap_transport_http::setCredentials()
Same name and namespace in other branches
  1. 5.2 includes/nusoap.php \soap_transport_http::setCredentials()
  2. 5.2 includes/nusoap.orig.php \soap_transport_http::setCredentials()

* if authenticating, set user credentials here * *

Parameters

string $username: * @param string $password * @param string $authtype (basic, digest, certificate) * @param array $digestRequest (keys must be nonce, nc, realm, qop) * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) * @access public

4 calls to soap_transport_http::setCredentials()
soap_transport_http::getResponse in includes/nusoap.php
soap_transport_http::getResponse in includes/nusoap.orig.php
soap_transport_http::setURL in includes/nusoap.php
soap_transport_http::setURL in includes/nusoap.orig.php

File

includes/nusoap.orig.php, line 2291

Class

soap_transport_http
transport class for sending/receiving data via HTTP and HTTPS NOTE: PHP must be compiled with the CURL extension for HTTPS support

Code

function setCredentials($username, $password, $authtype = 'basic', $digestRequest = [], $certRequest = []) {
  $this
    ->debug("Set credentials for authtype {$authtype}");

  // cf. RFC 2617
  if ($authtype == 'basic') {
    $this->outgoing_headers['Authorization'] = 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password);
  }
  elseif ($authtype == 'digest') {
    if (isset($digestRequest['nonce'])) {
      $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;

      // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
      // A1 = unq(username-value) ":" unq(realm-value) ":" passwd
      $A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;

      // H(A1) = MD5(A1)
      $HA1 = md5($A1);

      // A2 = Method ":" digest-uri-value
      $A2 = 'POST:' . $this->digest_uri;

      // H(A2)
      $HA2 = md5($A2);

      // KD(secret, data) = H(concat(secret, ":", data))
      // if qop == auth:
      // request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
      //                              ":" nc-value
      //                              ":" unq(cnonce-value)
      //                              ":" unq(qop-value)
      //                              ":" H(A2)
      //                            ) <">
      // if qop is missing,
      // request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
      $unhashedDigest = '';
      $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
      $cnonce = $nonce;
      if ($digestRequest['qop'] != '') {
        $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
      }
      else {
        $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
      }
      $hashedDigest = md5($unhashedDigest);
      $this->outgoing_headers['Authorization'] = 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"';
    }
  }
  elseif ($authtype == 'certificate') {
    $this->certRequest = $certRequest;
  }
  $this->username = $username;
  $this->password = $password;
  $this->authtype = $authtype;
  $this->digestRequest = $digestRequest;
  if (isset($this->outgoing_headers['Authorization'])) {
    $this
      ->debug('set Authorization: ' . substr($this->outgoing_headers['Authorization'], 0, 12) . '...');
  }
  else {
    $this
      ->debug('Authorization header not set');
  }
}