src/ForecastClient.php
public function authenticate($username, $password)
    {
        $authClient = $this->makeAuthClient();
        // Parse CSRF token from login form.
        $loginFormResponse = $authClient->get('/forecast/sign_in');
        $loginForm = $loginFormResponse->getBody()->getContents();
        $matches = [];
        $regexp = '/<input type="hidden" name="authenticity_token" value="(.*)"/';
        preg_match_all($regexp, $loginForm, $matches);
        $csrfToken = $matches[1][0];
        if (empty($csrfToken)) {
            throw new \Exception('CSRF token error - no token');
        }
        $data = [
            'authenticity_token' => $csrfToken,
            'email' => $username,
            'password' => $password,
            'product' => 'forecast'
        ];
        $sessionResponse = $authClient->post('/sessions', array('form_params' => $data));
        // Don't follow redirects on this one?
        $tokenRequestResponse = $authClient->get(sprintf('/accounts/%s', $this->accountId), array(
            'allow_redirects' => false,
        ));
        $tokenRequest = $tokenRequestResponse->getBody()->getContents();
        $matches = [];
        $regexp = '/access_token\/(.*)\?"/';
        preg_match_all($regexp, $tokenRequest, $matches);
        if (isset($matches[1][0]) && !empty($matches[1][0])) {
            $this->apiToken = $matches[1][0];

            // Remake the client so that it uses the api token authorization header.
            $this->guzzle = $this->makeClient();

            return $this->apiToken;
        } else {
            throw new \Exception('Could not find token. Check your login, password and APP ID');
        }
    }
public function authenticate($username, $password)
    {
        $authClient = $this->makeAuthClient();
        // Parse CSRF token from login form.
        $loginFormResponse = $authClient->get('/forecast/sign_in');
        $loginForm = $loginFormResponse->getBody()->getContents();
        $matches = [];
        $regexp = '/<input type="hidden" name="authenticity_token" value="(.*)"/';
        preg_match_all($regexp, $loginForm, $matches);
        $csrfToken = $matches[1][0];
        if (empty($csrfToken)) {
            throw new \Exception('CSRF token error - no token');
        }
        $data = [
            'authenticity_token' => $csrfToken,
            'email' => $username,
            'password' => $password,
            'product' => 'forecast'
        ];
        $sessionResponse = $authClient->post('/sessions', array('form_params' => $data));
        // Don't follow redirects on this one?
        $tokenRequestResponse = $authClient->get(sprintf('/accounts/%s', $this->accountId), array(
            'allow_redirects' => false,
        ));
        $tokenRequest = $tokenRequestResponse->getBody()->getContents();
        $matches = [];
        $regexp = '/access_token\/(.*)\?"/';
        preg_match_all($regexp, $tokenRequest, $matches);
        if (isset($matches[1][0]) && !empty($matches[1][0])) {
            $this->apiToken = $matches[1][0];

            // Remake the client so that it uses the api token authorization header.
            $this->guzzle = $this->makeClient();

            return $this->apiToken;
        } else {
            throw new \Exception('Could not find token. Check your login, password and APP ID');
        }
    }
@param string $username
@param string $password

@return null|string the API access token.
@throws \Exception