1
0
Fork 0

Ensure COMPOSER_AUTH takes precedence over local auth.json, fixes #12084

pull/12091/head
Jordi Boggiano 2024-08-21 18:38:51 +02:00
parent 47b924d27c
commit e173d20450
No known key found for this signature in database
1 changed files with 26 additions and 16 deletions

View File

@ -216,22 +216,7 @@ class Factory
}
$config->setAuthConfigSource(new JsonConfigSource($file, true));
// load COMPOSER_AUTH environment variable if set
if ($composerAuthEnv = Platform::getEnv('COMPOSER_AUTH')) {
$authData = json_decode($composerAuthEnv);
if (null === $authData) {
throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed, should be a valid JSON object');
} else {
if ($io instanceof IOInterface) {
$io->writeError('Loading auth config from COMPOSER_AUTH', true, IOInterface::DEBUG);
}
self::validateJsonSchema($io, $authData, JsonFile::AUTH_SCHEMA, 'COMPOSER_AUTH');
$authData = json_decode($composerAuthEnv, true);
if (null !== $authData) {
$config->merge(['config' => $authData], 'COMPOSER_AUTH');
}
}
}
self::loadComposerAuthEnv($config, $io);
return $config;
}
@ -341,6 +326,9 @@ class Factory
}
}
// make sure we load the auth env again over the local auth.json + composer.json config
self::loadComposerAuthEnv($config, $io);
$vendorDir = $config->get('vendor-dir');
// initialize composer
@ -678,6 +666,28 @@ class Factory
return $httpDownloader;
}
private static function loadComposerAuthEnv(Config $config, ?IOInterface $io): void
{
$composerAuthEnv = Platform::getEnv('COMPOSER_AUTH');
if (false === $composerAuthEnv || '' === $composerAuthEnv) {
return;
}
$authData = json_decode($composerAuthEnv);
if (null === $authData) {
throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed, should be a valid JSON object');
}
if ($io instanceof IOInterface) {
$io->writeError('Loading auth config from COMPOSER_AUTH', true, IOInterface::DEBUG);
}
self::validateJsonSchema($io, $authData, JsonFile::AUTH_SCHEMA, 'COMPOSER_AUTH');
$authData = json_decode($composerAuthEnv, true);
if (null !== $authData) {
$config->merge(['config' => $authData], 'COMPOSER_AUTH');
}
}
private static function useXdg(): bool
{
foreach (array_keys($_SERVER) as $key) {