コード例 #1
0
 /**
  * @test
  */
 public function shouldPreserveCredentials()
 {
     $this->assertSame($this->clientId, $this->credentials->clientId());
     $this->assertSame($this->clientSecret, $this->credentials->clientSecret());
     $this->assertSame($this->username, $this->credentials->username());
     $this->assertSame($this->password, $this->credentials->password());
 }
コード例 #2
0
 /**
  * Retrieve Salesforce access token.
  *
  * @param Credentials $credentials
  * @return AccessToken
  */
 public function getToken(Credentials $credentials)
 {
     try {
         $response = $this->client->post(sprintf("%s?grant_type=%s&client_id=%s&client_secret=%s&username=%s&password=%s", self::AUTH_ENDPOINT, self::GRANT_TYPE, $credentials->clientId(), $credentials->clientSecret(), $credentials->username(), $credentials->password()));
         $token = json_decode($response, true);
         return new AccessToken($token["access_token"], $token["instance_url"], $token["id"], $token["token_type"], $token["issued_at"], $token["signature"]);
     } catch (\Exception $e) {
         throw new \RuntimeException(sprintf("Could not retrieve access token with reason: %s", $e->getMessage()));
     }
 }