1
0
Fork 0

GitLab: detect invalid token setup and attempt to automatically resolve the issue for the user

pull/10748/head
Stephan Vock 2022-04-21 09:47:23 +01:00
parent 3b4a3d63bf
commit 89721ab322
No known key found for this signature in database
GPG Key ID: 257FEE7D686036D6
1 changed files with 8 additions and 1 deletions

View File

@ -92,7 +92,14 @@ class GitLab
if (isset($token)) {
$username = is_array($token) && array_key_exists("username", $token) ? $token["username"] : $token;
$password = is_array($token) && array_key_exists("token", $token) ? $token["token"] : 'private-token';
$this->io->setAuthentication($originUrl, $username, $password);
// Composer expects the GitLab token to be stored as username and 'private-token' or 'gitlab-ci-token' to be stored as password
// Detect cases where this is reversed and resolve automatically resolve it
if (in_array($username, array('private-token', 'gitlab-ci-token', 'oauth2'), true)) {
$this->io->setAuthentication($originUrl, $password, $username);
} else {
$this->io->setAuthentication($originUrl, $username, $password);
}
return true;
}