protected function getProxiedFuture() { if (!$this->future) { $params = $this->params; if (!$this->action) { throw new Exception(pht('You must %s!', 'setRawGitHubQuery()')); } if (!$this->accessToken) { throw new Exception(pht('You must %s!', 'setAccessToken()')); } $uri = new PhutilURI('https://api.github.com/'); $uri->setPath('/' . ltrim($this->action, '/')); $future = new HTTPSFuture($uri); $future->setData($this->params); $future->addHeader('Authorization', 'token ' . $this->accessToken); // NOTE: GitHub requires a 'User-Agent' header. $future->addHeader('User-Agent', __CLASS__); $future->setMethod($this->method); foreach ($this->headers as $header) { list($key, $value) = $header; $future->addHeader($key, $value); } $this->future = $future; } return $this->future; }
protected function loadOAuthAccountData() { $uri = new PhutilURI('https://api.github.com/user'); $uri->setQueryParam('access_token', $this->getAccessToken()); $future = new HTTPSFuture($uri); // NOTE: GitHub requires a User-Agent string. $future->addHeader('User-Agent', 'PhutilAuthAdapterOAuthGitHub'); list($body) = $future->resolvex(); $data = json_decode($body, true); if (!is_array($data)) { throw new Exception("Expected valid JSON response from GitHub account data request, " . "got: " . $body); } return $data; }
protected function loadOAuthAccountData() { $uri = new PhutilURI('https://api.github.com/user'); $uri->setQueryParam('access_token', $this->getAccessToken()); $future = new HTTPSFuture($uri); // NOTE: GitHub requires a User-Agent string. $future->addHeader('User-Agent', __CLASS__); list($body) = $future->resolvex(); try { return phutil_json_decode($body); } catch (PhutilJSONParserException $ex) { throw new PhutilProxyException(pht('Expected valid JSON response from GitHub account data request.'), $ex); } }
protected function getProxiedFuture() { if (!$this->future) { $params = $this->params; if (!$this->action) { throw new Exception('You must setRawTwitchQuery()!'); } if (!$this->accessToken) { throw new Exception('You must setAccessToken()!'); } $uri = new PhutilURI('https://api.twitch.tv/'); $uri->setPath('/kraken/' . ltrim($this->action, '/')); $uri->setQueryParam('oauth_token', $this->accessToken); $future = new HTTPSFuture($uri); $future->setData($this->params); $future->setMethod($this->method); // NOTE: This is how the Twitch API is versioned. $future->addHeader('Accept', 'application/vnd.twitchtv.2+json'); // NOTE: This is required to avoid rate limiting. $future->addHeader('Client-ID', $this->clientID); $this->future = $future; } return $this->future; }
protected function getProxiedFuture() { if (!$this->future) { $params = $this->params; if (!$this->action) { throw new Exception(pht('You must %s!', 'setRawAsanaQuery()')); } if (!$this->accessToken) { throw new Exception(pht('You must %s!', 'setAccessToken()')); } $uri = new PhutilURI('https://app.asana.com/'); $uri->setPath('/api/1.0/' . ltrim($this->action, '/')); $future = new HTTPSFuture($uri); $future->setData($this->params); $future->addHeader('Authorization', 'Bearer ' . $this->accessToken); $future->setMethod($this->method); $this->future = $future; } return $this->future; }
protected function getProxiedFuture() { if (!$this->future) { $params = $this->params; if (!$this->action) { throw new Exception("You must setRawWordPressQuery()!"); } if (!$this->accessToken) { throw new Exception("You must setAccessToken()!"); } $uri = new PhutilURI('https://public-api.wordpress.com/'); $uri->setPath('/rest/v1/' . ltrim($this->action, '/')); $future = new HTTPSFuture($uri); $future->setData($this->params); $future->setMethod($this->method); // NOTE: This is how WordPress.com REST API authenticates $future->addHeader('Authorization', 'Bearer ' . $this->accessToken); $this->future = $future; } return $this->future; }
public function callMethod($method, array $params) { $meta = array(); if ($this->sessionKey) { $meta['sessionKey'] = $this->sessionKey; } if ($this->connectionID) { $meta['connectionID'] = $this->connectionID; } if ($method == 'conduit.connect') { $certificate = idx($params, 'certificate'); if ($certificate) { $token = time(); $params['authToken'] = $token; $params['authSignature'] = sha1($token . $certificate); } unset($params['certificate']); } if ($meta) { $params['__conduit__'] = $meta; } $uri = id(clone $this->uri)->setPath('/api/' . $method); $data = array('params' => json_encode($params), 'output' => 'json', '__conduit__' => true); // Always use the cURL-based HTTPSFuture, for proxy support and other // protocol edge cases that HTTPFuture does not support. $core_future = new HTTPSFuture($uri, $data); $core_future->setMethod('POST'); $core_future->setTimeout($this->timeout); if ($this->basicAuthCredentials !== null) { $core_future->addHeader('Authorization', 'Basic ' . $this->basicAuthCredentials); } $conduit_future = new ConduitFuture($core_future); $conduit_future->setClient($this, $method); $conduit_future->beginProfile($data); $conduit_future->isReady(); return $conduit_future; }
public function callMethod($method, array $params) { $meta = array(); if ($this->sessionKey) { $meta['sessionKey'] = $this->sessionKey; } if ($this->connectionID) { $meta['connectionID'] = $this->connectionID; } if ($method == 'conduit.connect') { $certificate = idx($params, 'certificate'); if ($certificate) { $token = time(); $params['authToken'] = $token; $params['authSignature'] = sha1($token . $certificate); } unset($params['certificate']); } if ($this->privateKey && $this->publicKey) { $meta['auth.type'] = self::AUTH_ASYMMETRIC; $meta['auth.key'] = $this->publicKey; $meta['auth.host'] = $this->getHostStringForSignature(); $signature = $this->signRequest($method, $params, $meta); $meta['auth.signature'] = $signature; } if ($this->conduitToken) { $meta['token'] = $this->conduitToken; } if ($this->oauthToken) { $meta['access_token'] = $this->oauthToken; } if ($meta) { $params['__conduit__'] = $meta; } $uri = id(clone $this->uri)->setPath('/api/' . $method); $data = array('params' => json_encode($params), 'output' => 'json', '__conduit__' => true); // Always use the cURL-based HTTPSFuture, for proxy support and other // protocol edge cases that HTTPFuture does not support. $core_future = new HTTPSFuture($uri, $data); $core_future->addHeader('Host', $this->getHostStringForHeader()); $core_future->setMethod('POST'); $core_future->setTimeout($this->timeout); if ($this->username !== null) { $core_future->setHTTPBasicAuthCredentials($this->username, $this->password); } $conduit_future = new ConduitFuture($core_future); $conduit_future->setClient($this, $method); $conduit_future->beginProfile($data); $conduit_future->isReady(); return $conduit_future; }