Change user with Firebase Google user authentication

北慕城南 提交于 2019-12-10 01:43:58

问题


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.


回答1:


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




回答2:


You should sign out from Google explicitly:

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

Found the solution here




回答3:


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?




回答4:


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();
                }
            });

}

}




回答5:


Use this way to signout.

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

                    }

                 });


来源:https://stackoverflow.com/questions/33782838/change-user-with-firebase-google-user-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!