Skip to content

Commit 9289ed6

Browse files
committed
Check for existing token during two-factor login
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.
1 parent c6bdc12 commit 9289ed6

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

app/src/main/java/com/github/mobile/accounts/TwoFactorAuthActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ public User call() throws Exception {
221221
client.setOtpCode(otpCode);
222222

223223
OAuthService service = new OAuthService(client);
224-
String authToken = AccountAuthenticator.createAuthorization(service);
224+
String authToken = AccountAuthenticator.getAuthorization(service);
225+
if (authToken == null)
226+
authToken = AccountAuthenticator.createAuthorization(service);
225227
client.setOAuth2Token(authToken);
226228

227229
User user = new UserService(client).getUser();
@@ -257,4 +259,4 @@ public void onSuccess(User user) {
257259
};
258260
authenticationTask.execute();
259261
}
260-
}
262+
}

app/src/main/java/com/github/mobile/accounts/TwoFactorAuthClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public void setOtpCode(String otpCode) {
7171
@Override
7272
public GitHubResponse get(GitHubRequest request) throws IOException {
7373
HttpURLConnection httpRequest = createGet(request.generateUri());
74+
if (!TextUtils.isEmpty(otpCode))
75+
httpRequest.setRequestProperty(HEADER_OTP, otpCode);
76+
7477
try {
7578
String accept = request.getResponseContentType();
7679
if (accept != null)
@@ -147,4 +150,4 @@ private <V> V sendJson(final HttpURLConnection request,
147150
throw createException(getStream(request), code,
148151
request.getResponseMessage());
149152
}
150-
}
153+
}

0 commit comments

Comments
 (0)