Moved 401 handling from ComposerRepository to RemoteFilesystem and

displaying the url when asking for the credentials.
main
Stephan Hochdörfer 11 years ago
parent f2afbbac2f
commit dcdcf57f3f

@ -17,7 +17,6 @@ use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage;
use Composer\Package\Version\VersionParser;
use Composer\DependencyResolver\Pool;
use Composer\Downloader\TransportException;
use Composer\Json\JsonFile;
use Composer\Cache;
use Composer\Config;
@ -499,18 +498,6 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
continue;
}
// in case the remote filesystem responds with an 401 error ask for credentials
if($e instanceof TransportException && ($e->getCode() == 401))
{
$this->io->write('Enter the access credentials needed to access the repository');
$username = $this->io->ask('Username: ');
$password = $this->io->askAndHideAnswer('Password: ');
$this->rfs->setAuthentication($filename, $username, $password);
// try fetching the file again
return $this->fetchFile($filename, $cacheKey, $sha256);
}
if ($e instanceof RepositorySecurityException) {
throw $e;
}

@ -44,18 +44,6 @@ class RemoteFilesystem
$this->options = $options;
}
/**
* Set the authentication information for the repository.
*
* @param string $originUrl The origin URL
* @param string $username The username
* @param string $password The password
*/
public function setAuthentication($originUrl, $username, $password = null)
{
return $this->io->setAuthentication($originUrl, $username, $password);
}
/**
* Copy the remote file in local.
*
@ -137,6 +125,18 @@ class RemoteFilesystem
if ($e instanceof TransportException && !empty($http_response_header[0])) {
$e->setHeaders($http_response_header);
}
// in case the remote filesystem responds with an 401 error ask for credentials
if($e instanceof TransportException && ($e->getCode() == 401))
{
$this->io->write('Enter the access credentials needed to access the resource at '.$originUrl);
$username = $this->io->ask('Username: ');
$password = $this->io->askAndHideAnswer('Password: ');
$this->io->setAuthentication($originUrl, $username, $password);
// try getting the file again
return $this->get($originUrl, $fileUrl, $additionalOptions, $fileName, $progress);
}
}
if ($errorMessage && !ini_get('allow_url_fopen')) {
$errorMessage = 'allow_url_fopen must be enabled in php.ini ('.$errorMessage.')';

Loading…
Cancel
Save