New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Back-end changes for Google XOAUTH2 #1747
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lookin' good! Probably the most important PR we have currently, thanks for working on this 👍
@@ -82,4 +84,10 @@ public static String computeCramMd5(String username, String password, String b64 | |||
throw new MessagingException("Something went wrong during CRAM-MD5 computation", e); | |||
} | |||
} | |||
|
|||
public static String computeXoauth(String username, String authToken) throws UnsupportedEncodingException { | |||
return new String( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is packed with logic, a couple of intermediate steps probably couldn't hurt
public static boolean shouldRetry(String response, String host) { | ||
String decodedResponse = Base64.decode(response); | ||
|
||
Log.v(LOG_TAG, "Challenge response: "+ decodedResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a candidate for if (K9.DEBUG)
|
||
try { | ||
JSONObject json = new JSONObject(decodedResponse); | ||
if(!json.getString("status").equals(BAD_RESPONSE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style :)
also, CONSTANT.equals(variable) avoids NPEs
return false; | ||
} | ||
} catch (JSONException jsonException) { | ||
Log.i(LOG_TAG, "Error decoding JSON response from:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be Log.e
?
@@ -322,6 +329,14 @@ private void startTLS() throws IOException, MessagingException, GeneralSecurityE | |||
@SuppressWarnings("EnumSwitchStatementWhichMissesCases") | |||
private void authenticate() throws MessagingException, IOException { | |||
switch (settings.getAuthType()) { | |||
case XOAUTH2: | |||
if (hasCapability(Capabilities.AUTH_XOAUTH2) && hasCapability(Capabilities.SASL_IR) | |||
&& oauthTokenProvider != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case where oauthTokenProvider
is null here and it's not a bug? Either way it should probably be handled in an exception of its own, since the error message below is wrong in this case.
try { | ||
attemptXOAuth2(); | ||
} catch (NegativeImapResponseException e) { | ||
//We couldn't login with the token so invalidate it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointless comment :)
response.getString(0), settings.getHost()); | ||
} | ||
|
||
if(response.isContinuationRequested()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you try to be more careful about trivial style errors like this? android studio can do this for you (and us)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it was me I'd have a commit that fixed all the errors and made the build fail if new ones were added but nobody's a fan of that :(
I'll fix it.
@@ -635,6 +719,31 @@ protected String getLogId() { | |||
return responseParser.readStatusResponse(tag, commandToLog, getLogId(), untaggedHandler); | |||
} | |||
|
|||
public String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive) | |||
throws IOException, MessagingException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
@@ -109,7 +109,7 @@ private void readTaggedResponse(ImapResponseCallback callback) throws IOExceptio | |||
continue; | |||
} | |||
|
|||
if (untaggedHandler != null) { | |||
if (response.getTag() == null && untaggedHandler != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pointing out this might be a significant change in behavior, please double-check this doesn't break anything :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it only didn't fail a test because the test was badly written. I wrote some better tests for it and I think it should have failed. To me it looked like faulty logic and I browsed the spec a bit.
I'll keep using it on my device though.
} | ||
|
||
private CommandResponse executeSimpleCommandWithResponse(String command, boolean sensitive) throws IOException, MessagingException { | ||
List<String> results = new ArrayList<String>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diamond operator~
|
||
import java.util.List; | ||
|
||
public interface OAuth2TokenProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this interface actually implemented? don't see it in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not. This is just the back-end changes. That's an interface for the front-end to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK, makes sense, was confused because OAuth2TokenProvider sounds like back-end functionality. Does only authorizeAPI()
need user interaction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the expectation, yes.
An (imperfect) implementation that supports GMail only is here: https://github.com/philipwhiuk/k-9/commit/7bd0f52c6d24ba1696620c4109c30d1f06aa770f#diff-4e75c10b7bac153fec6888b448a738ea
02e9837
to
f9ed304
Compare
Thanks for that great work! I hope we'll get a release soon to try this great feature. |
I came here after some time of searching for open issues about Gmail OAuth logins. It's been around 1.5 years and as far as I could see I've not found OAuth support for logging into Gmail in the app. What's the current progress of this? |
@sivaraam Don't worry. Nothing has changed since your last message until now. |
Actually there is a PR #3804 that enables Gmail OAuth login. |
Splitting out from #1295