diff --git a/src/main/java/com/pokegoapi/auth/GoogleLogin.java b/src/main/java/com/pokegoapi/auth/GoogleLogin.java index 7378305b..ecddccb2 100644 --- a/src/main/java/com/pokegoapi/auth/GoogleLogin.java +++ b/src/main/java/com/pokegoapi/auth/GoogleLogin.java @@ -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; } /** @@ -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) { @@ -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); + } }