1
0
Fork 0

Handle envvar auth credentials as a JSON blob

As well as move the handling to a proper place
pull/4546/head
Oliver Vartiainen 2016-01-19 20:34:04 +02:00
parent aaee6dc0b0
commit b39b113fc3
2 changed files with 13 additions and 9 deletions

View File

@ -60,6 +60,19 @@ abstract class BaseIO implements IOInterface
*/ */
public function loadConfiguration(Config $config) public function loadConfiguration(Config $config)
{ {
// Use COMPOSER_AUTH environment variable if set
if ($envvar_data = getenv('COMPOSER_AUTH')) {
$auth_data = json_decode($envvar_data);
if (is_null($auth_data)) {
throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed');
}
foreach ($auth_data as $domain => $credentials) {
$this->setAuthentication($domain, $credentials->username, $credentials->password);
}
}
// reload oauth token from config if available // reload oauth token from config if available
if ($tokens = $config->get('github-oauth')) { if ($tokens = $config->get('github-oauth')) {
foreach ($tokens as $domain => $token) { foreach ($tokens as $domain => $token) {

View File

@ -207,15 +207,6 @@ class RemoteFilesystem
$this->retryAuthFailure = true; $this->retryAuthFailure = true;
$this->lastHeaders = array(); $this->lastHeaders = array();
// Use COMPOSER_AUTH environment variable if set
if (getenv('COMPOSER_AUTH')) {
$credentials = explode(':', getenv('COMPOSER_AUTH'), 2);
if (count($credentials) === 2) {
$this->io->setAuthentication($originUrl, $credentials[0], $credentials[1]);
}
}
// capture username/password from URL if there is one // capture username/password from URL if there is one
if (preg_match('{^https?://(.+):(.+)@([^/]+)}i', $fileUrl, $match)) { if (preg_match('{^https?://(.+):(.+)@([^/]+)}i', $fileUrl, $match)) {
$this->io->setAuthentication($originUrl, urldecode($match[1]), urldecode($match[2])); $this->io->setAuthentication($originUrl, urldecode($match[1]), urldecode($match[2]));