Adds support for token auth via username property.

Fixes gh-1602
This commit is contained in:
spencergibb
2021-03-29 18:05:38 -04:00
parent f4aab7f15d
commit e7a69671b3
2 changed files with 17 additions and 1 deletions

View File

@@ -96,6 +96,14 @@ public class GitCredentialsProviderFactory {
provider = new UsernamePasswordCredentialsProvider(username,
password.toCharArray());
}
else if (hasText(username) && !hasText(passphrase)) {
// useful for token based login gh-1602
// see
// https://stackoverflow.com/questions/28073266/how-to-use-jgit-to-push-changes-to-remote-with-oauth-access-token
this.logger.debug(
"Constructing UsernamePasswordCredentialsProvider for URI " + uri);
provider = new UsernamePasswordCredentialsProvider(username, (String) null);
}
else if (hasText(passphrase)) {
this.logger
.debug("Constructing PassphraseCredentialsProvider for URI " + uri);

View File

@@ -61,13 +61,21 @@ public class GitCredentialsProviderFactoryTests {
}
@Test
public void testCreateForFileWithUsername() {
public void testCreateForFileWithUsernameAndPassword() {
CredentialsProvider provider = this.factory.createFor(FILE_REPO, USER, PASSWORD,
null, false);
assertThat(provider).isNotNull();
assertThat(provider instanceof UsernamePasswordCredentialsProvider).isTrue();
}
@Test
public void testCreateForServerWithUsernameAndNoPassword() {
CredentialsProvider provider = this.factory.createFor(HTTPS_GIT_REPO, USER, "",
null, false);
assertThat(provider).isNotNull();
assertThat(provider instanceof UsernamePasswordCredentialsProvider).isTrue();
}
@Test
public void testCreateForServerNoUsernameIsNull() {
CredentialsProvider provider = this.factory.createFor(HTTPS_GIT_REPO, null, null,