當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::authenticate方法代碼示例

本文整理匯總了PHP中Github\Client::authenticate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::authenticate方法的具體用法?PHP Client::authenticate怎麽用?PHP Client::authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Github\Client的用法示例。


在下文中一共展示了Client::authenticate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: authenticate

 /**
  * Authenticates the current user for the upcoming API calls.
  */
 private function authenticate()
 {
     try {
         $this->client->authenticate($this->user->token, GitHubClient::AUTH_HTTP_TOKEN);
     } catch (\Exception $e) {
         \Bugsnag::notifyError('Exception', 'GitHub Authentication failed: ' . $e->getMessage());
     }
 }
開發者ID:cybercog,項目名稱:gistvote,代碼行數:11,代碼來源:GitHub.php

示例2: __construct

 /**
  * @param string $apiToken
  */
 public function __construct($apiToken = '')
 {
     $this->apiToken = $apiToken;
     $this->client = new Client();
     if ($apiToken) {
         $this->client->authenticate($apiToken, null, Client::AUTH_HTTP_TOKEN);
     }
 }
開發者ID:ostretsov,項目名稱:githubcmp,代碼行數:11,代碼來源:GithubRepositoryBuilder.php

示例3: __construct

 /**
  * @param string $token
  * @param Client $client
  */
 public function __construct($token = null, Client $client = null)
 {
     $this->client = $client ?: new Client(new CachedHttpClient());
     if ($token) {
         $this->client->authenticate($token, null, Client::AUTH_HTTP_PASSWORD);
     }
     parent::__construct();
 }
開發者ID:digitalkaoz,項目名稱:issues,代碼行數:12,代碼來源:GithubTracker.php

示例4: getGithubClient

 /**
  * @return Client
  */
 public function getGithubClient()
 {
     if (!$this->client) {
         $token = $this->container->getParameter('github')['api']['auth_token'];
         $this->client = new \Github\Client();
         $this->client->authenticate($token, null, \Github\Client::AUTH_HTTP_TOKEN);
     }
     return $this->client;
 }
開發者ID:loopline-systems,項目名稱:trello-github-issue-manager,代碼行數:12,代碼來源:GithubApi.php

示例5: __construct

 /**
  * コンストラクタ
  *
  * アクセストークンを利用して認証する
  *
  * @param string $access_token githubのアクセストークン
  * @param string $repo_owner   リポジトリのオーナー名
  * @param string $repo_name    リポジトリ名
  */
 public function __construct($access_token, $repo_owner, $repo_name)
 {
     $this->client = new \Github\Client();
     $this->client->authenticate($access_token, \Github\Client::AUTH_HTTP_TOKEN);
     $this->repo_owner = $repo_owner;
     $this->repo_name = $repo_name;
     $this->fh_pr = new JsonFile(sprintf(self::PR_SAVE_FILE_PATH_TPL, $repo_owner, $repo_name));
     $this->fh_comment = new JsonFile(sprintf(self::COMMENT_SAVE_FILE_PATH_TPL, $repo_owner, $repo_name));
 }
開發者ID:quelle,項目名稱:Githutil,代碼行數:18,代碼來源:PRWatcher.php

示例6: login

 public function login(array $credentials)
 {
     $this->user = $credentials['user'];
     $this->repo = $credentials['repo'];
     $this->client = new Client();
     $this->client->authenticate($credentials['oauth_token'], Client::AUTH_HTTP_TOKEN);
     $this->checkLogin();
     return $this;
 }
開發者ID:JesusLeon,項目名稱:Taskr,代碼行數:9,代碼來源:GithubApiRepository.php

示例7: createClient

 /**
  * @param string|null $accessToken
  * @return Client
  */
 public function createClient($accessToken = null)
 {
     $client = new Client();
     if ($this->token instanceof OAuthToken && null === $accessToken) {
         $client->authenticate($this->token->getAccessToken(), null, Client::AUTH_HTTP_TOKEN);
     } elseif (null !== $accessToken) {
         $client->authenticate($accessToken, null, Client::AUTH_HTTP_TOKEN);
     }
     return $client;
 }
開發者ID:approve-code,項目名稱:approve-code-webapp,代碼行數:14,代碼來源:GithubClientFactory.php

示例8: init

 public function init()
 {
     parent::init();
     $this->api = new Client();
     if ($this->enterpriseUrl) {
         $this->api->setEnterpriseUrl($this->enterpriseUrl);
     }
     $this->api->authenticate($this->authKey, null, Client::AUTH_URL_TOKEN);
     //$this->repoInfo = $this->api->repository()->show($this->owner, $this->repository);
 }
開發者ID:bariew,項目名稱:sitown,代碼行數:10,代碼來源:Github.php

示例9: __construct

 /**
  * @inheritdoc
  */
 public function __construct($token)
 {
     $cacheDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'snipper';
     // @codeCoverageIgnoreStart
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir);
     }
     // @codeCoverageIgnoreEnd
     $this->client = new Client(new CachedHttpClient(['cache_dir' => $cacheDir]));
     $this->client->authenticate($token, Client::AUTH_HTTP_TOKEN);
 }
開發者ID:ssgonchar,項目名稱:snipper,代碼行數:14,代碼來源:KnplabsClient.php

示例10: getClient

 /**
  * @return Client
  * @throws InvalidConfigurationException
  */
 protected function getClient()
 {
     if (!$this->client) {
         $this->client = $this->gitHubClientFactory->createClient();
         $token = $this->configProvider->getApiToken();
         if (empty($token)) {
             throw new InvalidConfigurationException('GitHub API token isn\'t set.');
         }
         $this->client->authenticate($token, null, Client::AUTH_URL_TOKEN);
     }
     return $this->client;
 }
開發者ID:rodolfobandeira,項目名稱:training-crm-application,代碼行數:16,代碼來源:GitHubCollaboratorManager.php

示例11: authenticateClient

 /**
  * Authenticates github client
  */
 private function authenticateClient()
 {
     $fileName = $_SERVER['HOME'] . '/.gh/.gh.yml';
     if (file_exists($fileName) && ($content = file_get_contents($fileName))) {
         $config = Yaml::parse($content);
         $token = isset($config['parameters']['token']) ? $config['parameters']['token'] : null;
         if (null === $token) {
             return;
         }
         $this->client = new Client();
         $this->client->authenticate($token, null, Client::AUTH_HTTP_TOKEN);
         return;
     }
 }
開發者ID:peterrehm,項目名稱:gh,代碼行數:17,代碼來源:Application.php

示例12: authenticate

 /**
  * @throws InvalidConfigurationException
  */
 public function authenticate()
 {
     $gitHubAccessToken = (string) Arrays::getValueByPath($this->gitHubSettings, 'contributor.accessToken');
     if (!$gitHubAccessToken) {
         throw new InvalidConfigurationException('The GitHub access token was not configured.', 1439627205);
     }
     $this->gitHubClient->authenticate($gitHubAccessToken, GithubClient::AUTH_HTTP_TOKEN);
     try {
         $userDetails = $this->gitHubClient->currentUser()->show();
         $this->currentUserLogin = $userDetails['login'];
     } catch (RuntimeException $exception) {
         throw new InvalidConfigurationException('It was not possible to authenticate to GitHub: ' . $exception->getMessage(), $exception->getCode());
     }
 }
開發者ID:kdambekalns,項目名稱:Neos.Contribute,代碼行數:17,代碼來源:GitHubService.php

示例13: handleResponse

 public function handleResponse(UserResponseInterface $response, UserService $userService)
 {
     $fields = $response->getResponse();
     $gitHubLogin = $fields['login'];
     $accessToken = $response->getAccessToken();
     $user = $userService->findByGitHubLogin($gitHubLogin);
     if (null === $user) {
         throw new UsernameNotFoundException();
     }
     $oAuthUser = new OAuthUser($user);
     $oAuthUser->addRole('ROLE_GITHUB_USER');
     $oAuthUser->setAccessToken($accessToken);
     if (array_key_exists('name', $fields)) {
         $gitHubName = $fields['name'];
         $oAuthUser->setRealName($gitHubName);
     } else {
         $oAuthUser->setRealName($gitHubLogin);
     }
     $client = new Client();
     $client->setOption('api_version', 'v3');
     $client->authenticate($response->getAccessToken(), Client::AUTH_HTTP_TOKEN);
     /* @var \Github\Api\CurrentUser $currentUserApi */
     $currentUserApi = $client->api('current_user');
     $emails = $currentUserApi->emails();
     $allEMails = $emails->all();
     $oAuthUser->setEmail($this->getPrimaryEmailAddress($allEMails));
     return $oAuthUser;
 }
開發者ID:terretta,項目名稱:gitki.php,代碼行數:28,代碼來源:GitHubResponseHandler.php

示例14: execute

 /**
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $changelog = array();
     $client = new Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache')));
     $client->authenticate($input->getArgument("token"), null, Client::AUTH_HTTP_TOKEN);
     $pullRequestAPI = $client->api('pull_request');
     $paginator = new ResultPager($client);
     $parameters = array($input->getArgument("organisation"), $input->getArgument("repository"), array('state' => 'closed'));
     $pullRequests = $paginator->fetchAll($pullRequestAPI, 'all', $parameters);
     $mergedPullRequests = array_filter($pullRequests, function ($pullRequest) {
         return !empty($pullRequest["merged_at"]);
     });
     foreach ($mergedPullRequests as $pullRequest) {
         if (empty($pullRequest['milestone'])) {
             $milestone = "No Milestone Selected";
         } else {
             $milestone = $pullRequest['milestone']['title'] . " / " . strftime("%Y-%m-%d", strtotime($pullRequest['milestone']['due_on']));
         }
         if (!array_key_exists($milestone, $changelog)) {
             $changelog[$milestone] = array();
         }
         $changelog[$milestone][] = $pullRequest;
     }
     uksort($changelog, 'version_compare');
     $changelog = array_reverse($changelog);
     echo "# Changelog";
     foreach ($changelog as $milestone => $pullRequests) {
         echo "\n\n## {$milestone}\n\n";
         foreach ($pullRequests as $pullRequest) {
             echo "* " . $pullRequest['title'] . " [#" . $pullRequest['number'] . "](" . $pullRequest['html_url'] . ") ([@" . $pullRequest['user']['login'] . "](" . $pullRequest['user']['html_url'] . ")) \n";
         }
     }
     //var_dump($changelog);
 }
開發者ID:kunstmaan,項目名稱:github-flow-changelog,代碼行數:39,代碼來源:ChangelogCommand.php

示例15: showPage

 public function showPage()
 {
     if (isset($_POST["register-data"]) && isset($_POST["register-password"])) {
         try {
             $client = new Client();
             $client->authenticate($_POST["register-data"], Client::AUTH_HTTP_TOKEN);
             $user = $client->api('current_user')->show();
             $repos = [];
             foreach ($client->api('current_user')->repositories('member', 'updated', 'desc') as $repo) {
                 $repos[] = ["name" => $repo["full_name"], "isPrivate" => $repo["private"]];
             }
             if (strlen($_POST["register-password"]) >= 6) {
                 Users::createUser($user["login"], $client->api('current_user')->emails()->all()[0], $_POST["register-password"], $_POST["register-data"], $repos);
                 Channels::addChannels($repos);
                 echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), ["user" => $user])]);
             } else {
                 echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), ["error" => "Passwords must be at least 6 characters long."])]);
             }
         } catch (\Exception $e) {
             echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), ["error" => "Oh no! Your registration couldn't be completed. Do you already have an account? Is your token valid?"])]);
         }
     } else {
         echo $this->getTemplateEngine()->render($this->getTemplateSnip("page"), ["title" => "Register", "content" => $this->getTemplateEngine()->render($this->getTemplate(), [])]);
     }
     //echo $this->getTemplateEngine()->render($this->getTemplate(), []);
 }
開發者ID:xpyctum,項目名稱:ShogChat,代碼行數:26,代碼來源:register.php


注:本文中的Github\Client::authenticate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。