コード例 #1
0
ファイル: Login.php プロジェクト: runt18/github-api-1
 /**
  * @param  string
  * @param  string
  * @return Token
  *
  * @throws LoginException
  */
 public function obtainToken($code, $state)
 {
     if ($state !== $this->storage->get('auth.state')) {
         throw new LoginException('OAuth security state does not match.');
     }
     $params = ['client_id' => $this->conf->clientId, 'client_secret' => $this->conf->clientSecret, 'code' => $code];
     $headers = ['Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'];
     $request = new Http\Request(Http\Request::POST, $this->tokenUrl, $headers, http_build_query($params));
     try {
         $response = $this->client->request($request);
     } catch (Http\BadResponseException $e) {
         throw new LoginException('HTTP request failed.', 0, $e);
     }
     try {
         /** @var $json \stdClass */
         if ($response->isCode(Http\Response::S404_NOT_FOUND)) {
             $json = Github\Helpers::jsonDecode($response->getContent());
             throw new LoginException($json->error, $response->getCode());
         } elseif (!$response->isCode(Http\Response::S200_OK)) {
             throw new LoginException('Unexpected response.', $response->getCode());
         }
         $json = Github\Helpers::jsonDecode($response->getContent());
     } catch (Github\JsonException $e) {
         throw new LoginException('Bad JSON in response.', 0, $e);
     }
     $token = new Token($json->access_token, $json->token_type, strlen($json->scope) ? explode(',', $json->scope) : []);
     $this->storage->set('auth.token', $token->toArray());
     $this->storage->remove('auth.state');
     return $token;
 }
コード例 #2
0
ファイル: CachedClient.php プロジェクト: JanTvrdik/github-api
 public function __construct(Storages\ICache $cache, IClient $client = NULL)
 {
     $this->cache = $cache;
     $this->client = $client ?: Github\Helpers::createDefaultClient();
 }
コード例 #3
0
ファイル: CachedClient.php プロジェクト: runt18/github-api-1
 /**
  * @param Storages\ICache
  * @param IClient
  * @param bool  forbid checking Github for new data; more or less development purpose only
  */
 public function __construct(Storages\ICache $cache, IClient $client = NULL, $forbidRecheck = FALSE)
 {
     $this->cache = $cache;
     $this->client = $client ?: Github\Helpers::createDefaultClient();
     $this->forbidRecheck = (bool) $forbidRecheck;
 }