Adds support for token auth via username property.
Fixes gh-1602
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user