Skip to content

Commit

Permalink
Merge pull request Grover-c13#181 from rajulbhatnagar/gauth_hook
Browse files Browse the repository at this point in the history
Add a callback for when the Initial oAuth completes so that the app c…
  • Loading branch information
Grover-c13 authored Jul 24, 2016
2 parents adab2ab + befed93 commit 3204bb7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/com/pokegoapi/auth/GoogleLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public class GoogleLogin extends Login {

private final OkHttpClient client;

private final OnGoogleLoginOAuthCompleteListener onGoogleLoginOAuthCompleteListener;

public GoogleLogin(OkHttpClient client) {
this.client = client;
onGoogleLoginOAuthCompleteListener = null;
}

public GoogleLogin(OkHttpClient client, OnGoogleLoginOAuthCompleteListener onGoogleLoginOAuthCompleteListener) {
this.client = client;
this.onGoogleLoginOAuthCompleteListener = onGoogleLoginOAuthCompleteListener;
}

/**
Expand Down Expand Up @@ -132,6 +140,9 @@ public AuthInfo login() throws LoginFailedException {
Log.d(TAG, "Get user to go to:"
+ googleAuth.getVerificationUrl()
+ " and enter code:" + googleAuth.getUserCode());
if (onGoogleLoginOAuthCompleteListener != null) {
onGoogleLoginOAuthCompleteListener.onInitialOAuthComplete(googleAuth);
}

GoogleAuthTokenJson token;
while ((token = poll(googleAuth)) == null) {
Expand Down Expand Up @@ -178,7 +189,15 @@ private GoogleAuthTokenJson poll(GoogleAuthJson json) throws URISyntaxException,
} else {
return null;
}

}

/**
* This callback will be called when we get the
* verification url and device code.
* This will allow applications to
* programmatically redirect user to redirect user.
*/
public interface OnGoogleLoginOAuthCompleteListener {
void onInitialOAuthComplete(GoogleAuthJson googleAuthJson);
}
}

0 comments on commit 3204bb7

Please sign in to comment.