Skip to content

Commit

Permalink
Merge pull request #27 from johnou/deprecated-password
Browse files Browse the repository at this point in the history
Password is no longer required for api usage and fix for broken base64 encoding.
  • Loading branch information
kohsuke committed Jan 7, 2013
2 parents bf1b0ed + f80cb54 commit ef241b1
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
public class GitHub {
/*package*/ final String login;
/*package*/ final String encodedAuthorization;
/*package*/ final String password;
/*package*/ final String apiToken;

private final Map<String,GHUser> users = new HashMap<String, GHUser>();
Expand All @@ -75,25 +74,24 @@ private GitHub(String login, String apiToken, String password) {
* The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or
* "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has <tt>/api/v3</tt> in the URL.
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
* Password is also considered deprecated as it is no longer required for api usage.
*/
private GitHub(String apiUrl, String login, String apiToken, String password) {
if (apiUrl.endsWith("/")) apiUrl = apiUrl.substring(0, apiUrl.length()-1); // normalize
this.apiUrl = apiUrl;
this.login = login;
this.apiToken = apiToken;
this.password = password;

if (apiToken!=null || password!=null) {
String userpassword = password==null ? (login + "/token" + ":" + apiToken) : (login + ':'+password);
encodedAuthorization = Base64.encodeBase64String(userpassword.getBytes());
String authorization = password==null ? (login + "/token" + ":" + apiToken) : (login + ':'+password);
encodedAuthorization = new String(Base64.encodeBase64(authorization.getBytes()));
} else
encodedAuthorization = null;
}

private GitHub (String apiUrl, String oauthAccessToken) throws IOException {

this.apiUrl = apiUrl;
this.password = null;
this.encodedAuthorization = null;

this.oauthAccessToken = oauthAccessToken;
Expand Down Expand Up @@ -126,9 +124,6 @@ public static GitHub connect() throws IOException {
* For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated.
*/
public static GitHub connectToEnterprise(String apiUrl, String login, String apiToken) {
// not exposing password because the login process still assumes https://github.com/
// if we are to fix this, fix that by getting rid of createWebClient() and replace the e-mail service hook
// with GitHub API.
return new GitHub(apiUrl,login,apiToken,null);
}

Expand Down

0 comments on commit ef241b1

Please sign in to comment.