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.htmlpull/5491/head
parent
b94e8ea21c
commit
997a062ebd
|
@ -63,6 +63,7 @@ class Config
|
|||
// bitbucket-oauth
|
||||
// github-oauth
|
||||
// gitlab-oauth
|
||||
// gitlab-token
|
||||
// http-basic
|
||||
);
|
||||
|
||||
|
@ -125,7 +126,7 @@ class Config
|
|||
// override defaults with given config
|
||||
if (!empty($config['config']) && is_array($config['config'])) {
|
||||
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);
|
||||
} elseif ('preferred-install' === $key && isset($this->config[$key])) {
|
||||
if (is_array($val) || is_array($this->config[$key])) {
|
||||
|
|
|
@ -64,6 +64,15 @@ class GitLab
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -714,6 +714,9 @@ class RemoteFilesystem
|
|||
if ($auth['password'] === 'oauth2') {
|
||||
$headers[] = 'Authorization: Bearer '.$auth['username'];
|
||||
}
|
||||
else if ($auth['password'] === 'private-token') {
|
||||
$headers[] = 'PRIVATE-TOKEN: '.$auth['username'];
|
||||
}
|
||||
} elseif ('bitbucket.org' === $originUrl
|
||||
&& $this->fileUrl !== Bitbucket::OAUTH2_ACCESS_TOKEN_URL && 'x-token-auth' === $auth['username']
|
||||
) {
|
||||
|
|
Loading…
Reference in New Issue