vendor/bjsmasth/php-salesforce-rest-api/src/Authentication/PasswordAuthentication.php line 30

Open in your IDE?
  1. <?php
  2. namespace bjsmasth\Salesforce\Authentication;
  3. use bjsmasth\Salesforce\Exception\SalesforceAuthentication;
  4. use GuzzleHttp\Client;
  5. class PasswordAuthentication implements AuthenticationInterface
  6. {
  7.     protected $client;
  8.     protected $endPoint;
  9.     protected $options;
  10.     protected $access_token;
  11.     protected $instance_url;
  12.     public function __construct(array $options)
  13.     {
  14.         if (session_status() === PHP_SESSION_NONE) {
  15.             session_start();
  16.         }
  17.         $this->endPoint 'https://login.salesforce.com/';
  18.         $this->options $options;
  19.     }
  20.     public function authenticate()
  21.     {
  22.         $client = new Client();
  23.         $request $client->request('post'$this->endPoint 'services/oauth2/token', ['form_params' => $this->options]);
  24.         $response json_decode($request->getBody(), true);
  25.         if ($response) {
  26.             $this->access_token $response['access_token'];
  27.             $this->instance_url $response['instance_url'];
  28.             $_SESSION['salesforce'] = $response;
  29.         } else {
  30.             throw new SalesforceAuthentication($request->getBody());
  31.         }
  32.     }
  33.     public function setEndpoint($endPoint)
  34.     {
  35.         $this->endPoint $endPoint;
  36.     }
  37.     public function getAccessToken()
  38.     {
  39.         return $this->access_token;
  40.     }
  41.     public function getInstanceUrl()
  42.     {
  43.         return $this->instance_url;
  44.     }
  45. }
  46. ?>