Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit c94fd0b

Browse files
committed
feature #6 [WIP] Added Two factor auth (lyrixx)
This PR was merged into the master branch. Discussion ---------- [WIP] Added Two factor auth fixes #2 blocked by KnpLabs/php-github-api#140 Commits ------- 10a5f66 [WIP] Added Two factor auth
2 parents fb3fcd4 + 10a5f66 commit c94fd0b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

GithubComment/Helper/GithubHelper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Client as Github;
66
use Github\Exception\RuntimeException;
7+
use Github\Exception\TwoFactorAuthenticationRequiredException;
78
use Symfony\Component\Console\Helper\Helper;
89
use Symfony\Component\Console\Input\InputInterface;
910
use Symfony\Component\Console\Output\OutputInterface;
@@ -44,6 +45,7 @@ public function getCredentials(InputInterface $input, OutputInterface $output)
4445
private function createToken(InputInterface $input, OutputInterface $output)
4546
{
4647
$dialog = $this->getHelperSet()->get('question');
48+
4749
$username = $dialog->ask($input, $output, new Question('<info>Your Github username:</info> '));
4850
$question = new Question('<info>Your Github password:</info> ');
4951
$question->setHidden(true);
@@ -55,6 +57,17 @@ private function createToken(InputInterface $input, OutputInterface $output)
5557
$token = $github->api('authorizations')->create(array('scopes' => array('repo'), 'note' => $this->name));
5658

5759
return ['username' => $username, 'token' => $token['token']];
60+
} catch (TwoFactorAuthenticationRequiredException $e) {
61+
try {
62+
$question = new Question('<info>The account has two-factor authentication enabled, please provide the code for this request:</info> ');
63+
$code = $dialog->ask($input, $output, $question);
64+
65+
$token = $github->api('authorizations')->create(array('scopes' => array('repo'), 'note' => $this->name), $code);
66+
67+
return array('username' => $username, 'token' => $token['token']);
68+
} catch (RuntimeException $e) {
69+
return false;
70+
}
5871
} catch (RuntimeException $e) {
5972
return false;
6073
}

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)