1
0
Fork 0

Support gitlab private-token (or personal-access-token) for easier access via gitlab API

Config example:

$HOME/.composer/auth.json

{
  "gitlab-token": {
    "gitlab.com": "YOUR-TOKEN-HERE"
  }
}

Gitlab API authentication doc: http://doc.gitlab.com/ce/api/README.html
pull/5491/head
moyo 2016-07-05 18:02:39 +08:00
parent b94e8ea21c
commit 997a062ebd
3 changed files with 14 additions and 1 deletions

View File

@ -63,6 +63,7 @@ class Config
// bitbucket-oauth // bitbucket-oauth
// github-oauth // github-oauth
// gitlab-oauth // gitlab-oauth
// gitlab-token
// http-basic // http-basic
); );
@ -125,7 +126,7 @@ class Config
// override defaults with given config // override defaults with given config
if (!empty($config['config']) && is_array($config['config'])) { if (!empty($config['config']) && is_array($config['config'])) {
foreach ($config['config'] as $key => $val) { foreach ($config['config'] as $key => $val) {
if (in_array($key, array('bitbucket-oauth', 'github-oauth', 'gitlab-oauth', 'http-basic')) && isset($this->config[$key])) { if (in_array($key, array('bitbucket-oauth', 'github-oauth', 'gitlab-oauth', 'gitlab-token', 'http-basic')) && isset($this->config[$key])) {
$this->config[$key] = array_merge($this->config[$key], $val); $this->config[$key] = array_merge($this->config[$key], $val);
} elseif ('preferred-install' === $key && isset($this->config[$key])) { } elseif ('preferred-install' === $key && isset($this->config[$key])) {
if (is_array($val) || is_array($this->config[$key])) { if (is_array($val) || is_array($this->config[$key])) {

View File

@ -64,6 +64,15 @@ class GitLab
return true; return true;
} }
// if available use token from composer config
$authTokens = $this->config->get('gitlab-token');
if (isset($authTokens[$originUrl])) {
$this->io->setAuthentication($originUrl, $authTokens[$originUrl], 'private-token');
return true;
}
return false; return false;
} }

View File

@ -714,6 +714,9 @@ class RemoteFilesystem
if ($auth['password'] === 'oauth2') { if ($auth['password'] === 'oauth2') {
$headers[] = 'Authorization: Bearer '.$auth['username']; $headers[] = 'Authorization: Bearer '.$auth['username'];
} }
else if ($auth['password'] === 'private-token') {
$headers[] = 'PRIVATE-TOKEN: '.$auth['username'];
}
} elseif ('bitbucket.org' === $originUrl } elseif ('bitbucket.org' === $originUrl
&& $this->fileUrl !== Bitbucket::OAUTH2_ACCESS_TOKEN_URL && 'x-token-auth' === $auth['username'] && $this->fileUrl !== Bitbucket::OAUTH2_ACCESS_TOKEN_URL && 'x-token-auth' === $auth['username']
) { ) {