Permalink
Browse files

Attempt user/pass authentication for git repos not on github

  • Loading branch information...
1 parent ce31449 commit 9d03dc5a899a1e6f4c1215034a509c681f4aa023 @machee machee committed Sep 30, 2012
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/Composer/Downloader/GitDownloader.php
View
30 src/Composer/Downloader/GitDownloader.php
@@ -199,6 +199,36 @@ protected function runCommand($commandCallable, $url, $path = null)
}
$retrying = true;
} while (--$retries);
+ } elseif (
+ $this->io->isInteractive() &&
+ preg_match('{(https?://)([^/]+/)(.*)$}i', $url, $match) &&
+ strpos($this->process->getErrorOutput(), 'fatal: Authentication failed') === 0
+ ) {
+ if ($saved = $this->io->hasAuthorization($match[1].$match[2])) {
+ $auth = $this->io->getAuthorization($match[1].$match[2]);
+ } else {
+ $this->io->write($match[1].$match[2].' ('.$match[3].') requires Authentication');
+ $auth = array(
+ 'username' => $this->io->ask('Username: '),
+ 'password' => $this->io->askAndHideAnswer('Password: '),
+ );
+ }
+
+ $url = $match[1].urlencode($auth['username']).':'.
+ urlencode($auth['password']).'@'.$match[2].$match[3];
+
+ $command = call_user_func($commandCallable, $url);
+ if (0 === $this->process->execute($command, $handler)) {
+ if (!$saved) {
+ $saved = $this->io->ask('Save user/pass for other requests to '.
+ $match[1].$match[2].' ? [y]/n: ');
+ if (in_array($saved, array('y', 'Y', null), true)) {
+ $this->io->setAuthorization($match[1].$match[2], $auth['username'], $auth['password']);
+ $this->io->write('saved...');
+ }
+ }
+ return;
+ }
}
if (null !== $path) {

0 comments on commit 9d03dc5

Please sign in to comment.