From cbec8ceb538e706467b9edbb4e43c7966b2f6ad6 Mon Sep 17 00:00:00 2001 From: Ethan Clevenger Date: Wed, 4 Mar 2020 15:01:35 -0800 Subject: [PATCH 1/2] Bearer support. --- src/Composer/IO/BaseIO.php | 5 +++++ src/Composer/Util/RemoteFilesystem.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Composer/IO/BaseIO.php b/src/Composer/IO/BaseIO.php index cb2e99def..d9dbc2d6f 100644 --- a/src/Composer/IO/BaseIO.php +++ b/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')); } diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 4885b7530..4fc6e8ed9 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -835,6 +835,8 @@ class RemoteFilesystem $headers[] = 'Authorization: Bearer ' . $auth['password']; $authenticationDisplayMessage = 'Using Bitbucket OAuth token authentication'; } + } elseif ($auth['password'] === 'bearer' ) { + $headers[] = 'Authorization: Bearer '.$auth['username']; } else { $authStr = base64_encode($auth['username'] . ':' . $auth['password']); $headers[] = 'Authorization: Basic '.$authStr; From 479414d8bd95d6ae0826c69e4a103366ef44200f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 10 Mar 2020 13:26:53 +0100 Subject: [PATCH 2/2] Move bearer auth to be first to make sure it does not get shadowed by github/gitlab/.. configs --- src/Composer/Util/RemoteFilesystem.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 4fc6e8ed9..2cb8025b7 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/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)) { @@ -835,8 +837,6 @@ class RemoteFilesystem $headers[] = 'Authorization: Bearer ' . $auth['password']; $authenticationDisplayMessage = 'Using Bitbucket OAuth token authentication'; } - } elseif ($auth['password'] === 'bearer' ) { - $headers[] = 'Authorization: Bearer '.$auth['username']; } else { $authStr = base64_encode($auth['username'] . ':' . $auth['password']); $headers[] = 'Authorization: Basic '.$authStr;