本文整理汇总了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());
}
}
示例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);
}
}
示例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();
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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());
}
}
示例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;
}
示例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);
}
示例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(), []);
}