public function authenticate() { $auth_url = "https://www.google.com/accounts/ClientLogin"; if (is_null(self::$curl)) { self::$curl = curl_init(); } $args = array('Email' => $this->api_key, 'Passwd' => $this->api_secret, 'accountType' => $this->account_type, 'service' => 'apps', 'source' => 'twilio-openVBX-1.0', 'logintoken' => $this->login_token, 'logincaptcha' => $this->login_captcha); error_log(var_export($args, true)); curl_setopt(self::$curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); curl_setopt(self::$curl, CURLOPT_POST, true); curl_setopt(self::$curl, CURLOPT_POSTFIELDS, http_build_query($args)); curl_setopt(self::$curl, CURLOPT_RETURNTRANSFER, true); curl_setopt(self::$curl, CURLOPT_URL, $auth_url); $response = curl_exec(self::$curl); $response = explode("\n", $response); $auth_response = array(); foreach ($response as $response_pair) { $response_pair = explode('=', $response_pair); $auth_response[$response_pair[0]] = isset($response_pair[1]) ? $response_pair[1] : ''; $auth_response[$response_pair[0]] .= isset($response_pair[2]) ? '=' . $response_pair[2] : ''; } if (!empty($auth_response['Auth'])) { $this->auth_token = $auth_response['Auth']; $this->authenticated = true; return $this->authenticated; } if (!empty($auth_response['Error'])) { $this->auth_response = $auth_response; $error_code = GoogleLoginChallenge::get_error_code($auth_response['Error']); $error_message = GoogleLoginChallenge::get_error_message($auth_response['Error']); throw new GoogleUtilityClientException($error_message, $error_code); } }