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

main
Stephan Vock 2 years ago
parent 3b4a3d63bf
commit 89721ab322
No known key found for this signature in database
GPG Key ID: 257FEE7D686036D6

@ -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;
}

Loading…
Cancel
Save