19

When using Firebase Google user authentication the user is immediately logged in if they have already authorized the application and only logged in to one Google account.

Is there a way to force the "Choose an account" dialog to appear so that the user has the opportunity to login to a different Google account or create a new one?

Currency as far as I know the user has to manually logout of the current Google account (or login to > 1) from Google.com to make the dialog appear.

bostondv
  • 415
  • 4
  • 8

6 Answers6

29

You can force to choose an account with 'prompt' provider parameter.

var googleAuthProvider = new firebase.auth.GoogleAuthProvider();
googleAuthProvider.setCustomParameters({
   prompt: 'select_account'
});
firebase.auth().signInWithRedirect(googleAuthProvider)

Tested with Firebase JavaScript SDK v4.1.2

Misha
  • 291
  • 3
  • 7
3

You should sign out from Google explicitly:

Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(status -> {
    mFirebaseAuth.signOut();
});

Found the solution here

Rick
  • 1,177
  • 1
  • 19
  • 27
1

I'm trying to figure out the same thing. According to some Google documentation, it appears that you can force the account chooser with a "prompt" command (of "none", "select_account" or "consent"):

Force google account chooser

...however there appears to be no way to set the "prompt" value in any of Firebase's authentication methods (specifically authWithOAuthRedirect and authWithOAuthPopup).

Were you ever able to figure it out?

Community
  • 1
  • 1
hairbo
  • 3,113
  • 2
  • 27
  • 34
  • I ended up building my own authentication using [Google Sign-In](https://developers.google.com/identity/sign-in/web/sign-in), [Firebase Custom Authentication](https://www.firebase.com/docs/web/guide/login/custom.html) and [this node.js oauth proxy](https://www.npmjs.com/package/google-firebase-auth-proxy). Not ideal but I couldn't find any other way to do it with Firebase's Google Auth method... – bostondv Dec 10 '15 at 21:21
  • I contacted Firebase support about this, and they confirmed that there's no way currently to force the Google "Account Chooser" page, but they seemed to think it was a good idea, so perhaps they'll sneak it into a future update. – hairbo Dec 11 '15 at 22:04
1

In my following code, the gooogle sign-in button every time prompts for choosing account...

public class MainActivity extends AppCompatActivity {

Button btn_signOut;
private GoogleSignInClient mGoogleSignInClient;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn_signOut = findViewById(R.id.btnSignOut);

    btn_signOut.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            signOut();
        }
    });

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}

private void signOut() {
    mGoogleSignInClient.signOut()
            .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    finish();
                }
            });

}

}

SjCodes
  • 29
  • 2
0

Use this way to signout.

 Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new
 ResultCallback<Status>()
                 {
                     @Override
                    public void onResult(@NonNull Status status)
                     {
                         mAuth.signOut();

                    }

                 });
A P
  • 2,131
  • 2
  • 24
  • 36
subbu
  • 51
  • 3
0

In flutter, use: GoogleSignIn().signOut();

(assumming you used the google_sign_in package)