Skip to content

Commit

Permalink
Fix two-factor authentication
Browse files Browse the repository at this point in the history
GitHub now only allows seeing generated tokens when they are created,
so we need to create one on each login.

Fixes #46
  • Loading branch information
jonan committed Sep 15, 2015
1 parent 12d8ed1 commit fe7bdd1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static android.accounts.AccountManager.KEY_INTENT;
import static com.github.mobile.accounts.AccountConstants.ACCOUNT_TYPE;
import static com.github.mobile.accounts.AccountConstants.APP_NOTE;
import static com.github.mobile.accounts.AccountConstants.APP_NOTE_URL;
import static com.github.mobile.accounts.LoginActivity.PARAM_AUTHTOKEN_TYPE;
import static com.github.mobile.accounts.LoginActivity.PARAM_USERNAME;
import android.accounts.AbstractAccountAuthenticator;
Expand Down Expand Up @@ -97,12 +96,6 @@ private static boolean isValidAuthorization(final Authorization auth,
if (auth == null)
return false;

if (!APP_NOTE.equals(auth.getNote()))
return false;

if (!APP_NOTE_URL.equals(auth.getNoteUrl()))
return false;

List<String> scopes = auth.getScopes();
return scopes != null && scopes.containsAll(requiredScopes);
}
Expand Down Expand Up @@ -137,8 +130,7 @@ public static String getAuthorization(final OAuthService service) throws IOExcep
*/
public static String createAuthorization(final OAuthService service) throws IOException {
Authorization auth = new Authorization();
auth.setNote(APP_NOTE);
auth.setNoteUrl(APP_NOTE_URL);
auth.setNote(APP_NOTE + " " + System.currentTimeMillis());
auth.setScopes(SCOPES);
auth = service.createAuthorization(auth);
return auth != null ? auth.getToken() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ public User call() throws Exception {
client.setOtpCode(otpCode);

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

User user = new UserService(client).getUser();
Expand Down

0 comments on commit fe7bdd1

Please sign in to comment.