Browse Source

Store and reload the github token to/from the config

Jordi Boggiano 12 years ago
parent
commit
a9811c4e40
2 changed files with 12 additions and 0 deletions
  1. 7 0
      src/Composer/Factory.php
  2. 5 0
      src/Composer/Repository/Vcs/GitHubDriver.php

+ 7 - 0
src/Composer/Factory.php

@@ -140,6 +140,13 @@ class Factory
         $config = static::createConfig();
         $config->merge($localConfig);
 
+        // reload oauth token from config if available
+        if ($tokens = $config->get('github-oauth')) {
+            foreach ($tokens as $domain => $token) {
+                $io->setAuthorization($domain, $token, 'x-oauth-basic');
+            }
+        }
+
         $vendorDir = $config->get('vendor-dir');
         $binDir = $config->get('bin-dir');
 

+ 5 - 0
src/Composer/Repository/Vcs/GitHubDriver.php

@@ -373,6 +373,11 @@ class GitHubDriver extends VcsDriver
 
             $this->io->setAuthorization($this->originUrl, $contents['token'], 'x-oauth-basic');
 
+            // store value in user config
+            $githubTokens = $this->config->get('github-oauth') ?: array();
+            $githubTokens[$this->originUrl] = $contents['token'];
+            $this->config->getConfigSource()->addConfigSetting('github-oauth', $githubTokens);
+
             return;
         }