src/Auth.php
public function authenticate($username, $password) {

    // Get some things.
    $client = $this->getClient();
    $parameters = $this->getAuthParams();
    $endpoint = $this->getEndpoint();
    $code = NULL;

    $response = $client->get($endpoint,
      ['query' => $parameters, 'auth' => [$username, $password]]
    );

    $code = $response->getStatusCode();
    $this->setLastResponse($response);

    // @todo: handle non 200 responses with error logging.
    switch ($code) {
      case '200':
        $body = $response->getBody();
        $json = json_decode($body->getContents());
        if (empty($json)) {
          throw new \Exception("Could not get JSON from body.");
        }
        $this->setAuthApiToken($json->access_token);
        $this->setAuthApiTokenExpires($json->expires_in);
        break;
    }

    return $this;
  }
public function authenticate($username, $password) {

    // Get some things.
    $client = $this->getClient();
    $parameters = $this->getAuthParams();
    $endpoint = $this->getEndpoint();
    $code = NULL;

    $response = $client->get($endpoint,
      ['query' => $parameters, 'auth' => [$username, $password]]
    );

    $code = $response->getStatusCode();
    $this->setLastResponse($response);

    // @todo: handle non 200 responses with error logging.
    switch ($code) {
      case '200':
        $body = $response->getBody();
        $json = json_decode($body->getContents());
        if (empty($json)) {
          throw new \Exception("Could not get JSON from body.");
        }
        $this->setAuthApiToken($json->access_token);
        $this->setAuthApiTokenExpires($json->expires_in);
        break;
    }

    return $this;
  }
public function authenticate ( $ username , $ password ) { // Get some things. $ client = $ this -> getClient ( ) ; $ parameters = $ this -> getAuthParams ( ) ; $ endpoint = $ this -> getEndpoint ( ) ; $ code = NULL ; $ response = $ client -> get ( $ endpoint , [ 'query' => $ parameters , 'auth' => [ $ username , $ password ] ] ) ; $ code = $ response -> getStatusCode ( ) ; $ this -> setLastResponse ( $ response ) ; // @todo: handle non 200 responses with error logging. switch ( $ code ) { case '200' : $ body = $ response -> getBody ( ) ; $ json = json_decode ( $ body -> getContents ( ) ) ; if ( empty ( $ json ) ) { throw new \ Exception ( "Could not get JSON from body." ) ; } $ this -> setAuthApiToken ( $ json -> access_token ) ; $ this -> setAuthApiTokenExpires ( $ json -> expires_in ) ; break ; } return $ this ; }
Authenticates a username and password with the CAP API.

Response returns an API token and expires integer. The API token can then
be used in future API calls to protected parts of the API.

@return bool
True for success and false for some issue.
Authenticates a username and password with the CAP API .