Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 564472b

Browse files
committed
Logout user from Google Auth as well
1 parent b05fe34 commit 564472b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.zulip.android.networking.response.UserConfigurationResponse;
3737
import com.zulip.android.networking.response.events.EventsBranch;
3838
import com.zulip.android.service.ZulipServices;
39+
import com.zulip.android.util.GoogleAuthHelper;
3940
import com.zulip.android.util.ZLog;
4041

4142
import java.io.IOException;
@@ -398,6 +399,8 @@ public void logOut() {
398399
ed.apply();
399400
this.api_key = null;
400401
setEventQueueId(null);
402+
403+
new GoogleAuthHelper().logOutGoogleAuth();
401404
}
402405

403406
public String getEmail() {
@@ -527,4 +530,5 @@ public void onFailure(Call<ResponseBody> call, Throwable t) {
527530
}
528531
});
529532
}
533+
530534
}

app/src/main/java/com/zulip/android/activities/LoginActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ private void setupGoogleSignIn() {
346346
.build();
347347

348348
mGoogleApiClient.connect();
349+
349350
allowUserToPickAccount();
350351
} else {
351352
allowUserToPickAccount();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.zulip.android.util;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.util.Log;
6+
7+
import com.google.android.gms.auth.api.Auth;
8+
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
9+
import com.google.android.gms.common.api.GoogleApiClient;
10+
import com.zulip.android.BuildConfig;
11+
import com.zulip.android.ZulipApp;
12+
13+
/**
14+
* Class to encapsulate logic for the Google Authentication flows
15+
*/
16+
17+
public class GoogleAuthHelper implements GoogleApiClient.ConnectionCallbacks {
18+
19+
private GoogleApiClient mGoogleApiClient;
20+
21+
public void logOutGoogleAuth() {
22+
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
23+
.requestEmail()
24+
.requestIdToken(BuildConfig.GOOGLE_CLIENT_ID)
25+
.build();
26+
27+
mGoogleApiClient = new GoogleApiClient.Builder(ZulipApp.get())
28+
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
29+
.addConnectionCallbacks(this)
30+
.build();
31+
32+
mGoogleApiClient.connect();
33+
}
34+
35+
@Override
36+
public void onConnected(@Nullable Bundle bundle) {
37+
Auth.GoogleSignInApi.signOut(mGoogleApiClient);
38+
}
39+
40+
@Override
41+
public void onConnectionSuspended(int i) {
42+
// do nothing
43+
}
44+
}

0 commit comments

Comments
 (0)