Skip to content

Commit

Permalink
Check for existing token during two-factor login
Browse files Browse the repository at this point in the history
OAuth2 token notes must be unique so without this check a
login from a 2nd device will fail when it tries to create an
authorization and one already exists.
  • Loading branch information
kevinsawicki committed Feb 21, 2014
1 parent c6bdc12 commit 9289ed6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ public User call() throws Exception {
client.setOtpCode(otpCode);

OAuthService service = new OAuthService(client);
String authToken = AccountAuthenticator.createAuthorization(service);
String authToken = AccountAuthenticator.getAuthorization(service);
if (authToken == null)
authToken = AccountAuthenticator.createAuthorization(service);
client.setOAuth2Token(authToken);

User user = new UserService(client).getUser();
Expand Down Expand Up @@ -257,4 +259,4 @@ public void onSuccess(User user) {
};
authenticationTask.execute();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void setOtpCode(String otpCode) {
@Override
public GitHubResponse get(GitHubRequest request) throws IOException {
HttpURLConnection httpRequest = createGet(request.generateUri());
if (!TextUtils.isEmpty(otpCode))
httpRequest.setRequestProperty(HEADER_OTP, otpCode);

try {
String accept = request.getResponseContentType();
if (accept != null)
Expand Down Expand Up @@ -147,4 +150,4 @@ private <V> V sendJson(final HttpURLConnection request,
throw createException(getStream(request), code,
request.getResponseMessage());
}
}
}

0 comments on commit 9289ed6

Please sign in to comment.