瀏覽代碼

Update the way github authorization is handled, fixes #1632

Since api.github.com redirects to s3 for downloads and s3 does not like Authorization
headers, we have to rely on the access_token query param. Otherwise php follows redirects
but still sends the Authorization header to all following requests.
Jordi Boggiano 12 年之前
父節點
當前提交
5b1f3145c2
共有 1 個文件被更改,包括 10 次插入2 次删除
  1. 10 2
      src/Composer/Util/RemoteFilesystem.php

+ 10 - 2
src/Composer/Util/RemoteFilesystem.php

@@ -101,6 +101,10 @@ class RemoteFilesystem
         $this->lastProgress = null;
 
         $options = $this->getOptionsForUrl($originUrl, $additionalOptions);
+        if (isset($options['github-token'])) {
+            $fileUrl .= (false === strpos($fileUrl, '?') ? '?' : '&') . 'access_token='.$options['github-token'];
+            unset($options['github-token']);
+        }
         $ctx = StreamContextFactory::getContext($options, array('notification' => array($this, 'callbackGet')));
 
         if ($this->progress) {
@@ -281,8 +285,12 @@ class RemoteFilesystem
 
         if ($this->io->hasAuthentication($originUrl)) {
             $auth = $this->io->getAuthentication($originUrl);
-            $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
-            $headers[] = 'Authorization: Basic '.$authStr;
+            if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) {
+                $options['github-token'] = $auth['username'];
+            } else {
+                $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
+                $headers[] = 'Authorization: Basic '.$authStr;
+            }
         }
 
         $options = array_replace_recursive($this->options, $additionalOptions);