2121import android .os .Bundle ;
2222import android .os .CancellationSignal ;
2323import android .util .Log ;
24+
25+ import androidx .annotation .NonNull ;
2426import androidx .appcompat .app .AppCompatActivity ;
27+ import androidx .credentials .ClearCredentialStateRequest ;
2528import androidx .credentials .Credential ;
2629import androidx .credentials .CredentialManager ;
2730import androidx .credentials .CredentialManagerCallback ;
2831import androidx .credentials .CustomCredential ;
2932import androidx .credentials .GetCredentialRequest ;
3033import androidx .credentials .GetCredentialResponse ;
34+ import androidx .credentials .exceptions .ClearCredentialException ;
3135import androidx .credentials .exceptions .GetCredentialException ;
3236import com .google .android .libraries .identity .googleid .GetGoogleIdOption ;
3337import com .google .android .libraries .identity .googleid .GoogleIdTokenCredential ;
@@ -126,7 +130,7 @@ private void createGoogleIdToken(Credential credential) {
126130 // Sign in to Firebase with using the token
127131 firebaseAuthWithGoogle (googleIdTokenCredential .getIdToken ());
128132 } else {
129- Log .d (TAG , "Credential is not of type Google ID!" );
133+ Log .w (TAG , "Credential is not of type Google ID!" );
130134 }
131135 }
132136 // [END create_google_id_token]
@@ -150,6 +154,31 @@ private void firebaseAuthWithGoogle(String idToken) {
150154 }
151155 // [END auth_with_google]
152156
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+
153182 private void updateUI (FirebaseUser user ) {
154183
155184 }
0 commit comments