Selaa lähdekoodia

Merge remote-tracking branch 'firoxer/envvar_auth'

Jordi Boggiano 9 vuotta sitten
vanhempi
commit
e513f27674
1 muutettua tiedostoa jossa 13 lisäystä ja 0 poistoa
  1. 13 0
      src/Composer/IO/BaseIO.php

+ 13 - 0
src/Composer/IO/BaseIO.php

@@ -60,6 +60,19 @@ abstract class BaseIO implements IOInterface
      */
     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
         if ($tokens = $config->get('github-oauth')) {
             foreach ($tokens as $domain => $token) {