21
21
import android .os .Bundle ;
22
22
import android .os .CancellationSignal ;
23
23
import android .util .Log ;
24
+
25
+ import androidx .annotation .NonNull ;
24
26
import androidx .appcompat .app .AppCompatActivity ;
27
+ import androidx .credentials .ClearCredentialStateRequest ;
25
28
import androidx .credentials .Credential ;
26
29
import androidx .credentials .CredentialManager ;
27
30
import androidx .credentials .CredentialManagerCallback ;
28
31
import androidx .credentials .CustomCredential ;
29
32
import androidx .credentials .GetCredentialRequest ;
30
33
import androidx .credentials .GetCredentialResponse ;
34
+ import androidx .credentials .exceptions .ClearCredentialException ;
31
35
import androidx .credentials .exceptions .GetCredentialException ;
32
36
import com .google .android .libraries .identity .googleid .GetGoogleIdOption ;
33
37
import com .google .android .libraries .identity .googleid .GoogleIdTokenCredential ;
@@ -126,7 +130,7 @@ private void createGoogleIdToken(Credential credential) {
126
130
// Sign in to Firebase with using the token
127
131
firebaseAuthWithGoogle (googleIdTokenCredential .getIdToken ());
128
132
} else {
129
- Log .d (TAG , "Credential is not of type Google ID!" );
133
+ Log .w (TAG , "Credential is not of type Google ID!" );
130
134
}
131
135
}
132
136
// [END create_google_id_token]
@@ -150,6 +154,31 @@ private void firebaseAuthWithGoogle(String idToken) {
150
154
}
151
155
// [END auth_with_google]
152
156
157
+ // [START sign_out]
158
+ private void signOut () {
159
+ // Firebase sign out
160
+ mAuth .signOut ();
161
+
162
+ // When a user signs out, clear the current user credential state from all credential providers.
163
+ ClearCredentialStateRequest clearRequest = new ClearCredentialStateRequest ();
164
+ credentialManager .clearCredentialStateAsync (
165
+ clearRequest ,
166
+ new CancellationSignal (),
167
+ Executors .newSingleThreadExecutor (),
168
+ new CredentialManagerCallback <>() {
169
+ @ Override
170
+ public void onResult (@ NonNull Void result ) {
171
+ updateUI (null );
172
+ }
173
+
174
+ @ Override
175
+ public void onError (@ NonNull ClearCredentialException e ) {
176
+ Log .e (TAG , "Couldn't clear user credentials: " + e .getLocalizedMessage ());
177
+ }
178
+ });
179
+ }
180
+ // [END sign_out]
181
+
153
182
private void updateUI (FirebaseUser user ) {
154
183
155
184
}
0 commit comments