Browse Source

Merge pull request #8671 from ethanclevenger91/ethanclevenger91/explicit-bearer-support

Bearer support.
Jordi Boggiano 5 years ago
parent
commit
0b993ba4b9
2 changed files with 8 additions and 1 deletions
  1. 5 0
      src/Composer/IO/BaseIO.php
  2. 3 1
      src/Composer/Util/RemoteFilesystem.php

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

@@ -116,6 +116,7 @@ abstract class BaseIO implements IOInterface, LoggerInterface
         $gitlabOauth = $config->get('gitlab-oauth') ?: array();
         $gitlabToken = $config->get('gitlab-token') ?: array();
         $httpBasic = $config->get('http-basic') ?: array();
+        $bearerToken = $config->get('bearer') ?: array();
 
         // reload oauth tokens from config if available
 
@@ -143,6 +144,10 @@ abstract class BaseIO implements IOInterface, LoggerInterface
             $this->checkAndSetAuthentication($domain, $cred['username'], $cred['password']);
         }
 
+        foreach ($bearerToken as $domain => $token) {
+            $this->checkAndSetAuthentication($domain, $token, 'bearer');
+        }
+
         // setup process timeout
         ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
     }

+ 3 - 1
src/Composer/Util/RemoteFilesystem.php

@@ -817,7 +817,9 @@ class RemoteFilesystem
         if ($this->io->hasAuthentication($originUrl)) {
             $authenticationDisplayMessage = null;
             $auth = $this->io->getAuthentication($originUrl);
-            if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) {
+            if ($auth['password'] === 'bearer') {
+                $headers[] = 'Authorization: Bearer '.$auth['username'];
+            } elseif ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) {
                 $options['github-token'] = $auth['username'];
                 $authenticationDisplayMessage = 'Using GitHub token authentication';
             } elseif ($this->config && in_array($originUrl, $this->config->get('gitlab-domains'), true)) {