Skip to content

Commit f9cce87

Browse files
Git credentials
1 parent ec90682 commit f9cce87

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/org/fugerit/java/github/issue/export/GithubIssueExport.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import java.net.PasswordAuthentication;
1111
import java.net.Proxy;
1212
import java.net.URL;
13-
import java.net.URLEncoder;
13+
import java.nio.charset.StandardCharsets;
1414
import java.util.ArrayList;
15+
import java.util.Base64;
1516
import java.util.Iterator;
1617
import java.util.List;
1718
import java.util.Locale;
@@ -237,9 +238,6 @@ private static String readUrlData( String url, GithubIssueInfo info ) throws Exc
237238
String githubUser = info.getProperty( ARG_GITHUB_USER );
238239
String githubPass = info.getProperty( ARG_GITHUB_PASS );
239240
logger.info( "connecting to url : "+url+" (user:"+githubUser+")" );
240-
if ( StringUtils.isNotEmpty( githubUser ) && StringUtils.isNotEmpty( githubPass ) ) {
241-
url = url.replace( "api.github.com" , githubUser+":"+URLEncoder.encode( githubPass, "UTF-8" )+"@api.github.com" );
242-
}
243241
HttpURLConnection conn;
244242
if ( !StringUtils.isEmpty( proxyHost ) && !StringUtils.isEmpty( proxyPort ) ) {
245243
logger.debug( "using proxy : "+proxyHost+":"+proxyPort+" (user:"+proxyUser+")" );
@@ -257,6 +255,11 @@ public PasswordAuthentication getPasswordAuthentication() {
257255
} else {
258256
URL u = new URL( url );
259257
conn = (HttpURLConnection)u.openConnection();
258+
if ( StringUtils.isNotEmpty( githubUser ) && StringUtils.isNotEmpty( githubPass ) ) {
259+
String encoded = Base64.getEncoder().encodeToString((githubUser+":"+githubPass).getBytes(StandardCharsets.UTF_8));
260+
logger.info( "Set authentication : "+encoded );
261+
conn.setRequestProperty("Authorization", "Basic "+encoded);
262+
}
260263
}
261264
StringBuffer buffer = new StringBuffer();
262265
if ( conn.getResponseCode() != 200 ) {

0 commit comments

Comments
 (0)