FeedMeData
FeedMeData

Reputation: 71

Android - How to link multiple Auth Providers to an account i.e google and Email/Password

I have checked the documentation however, I do not understand where the link is to connect the accounts. I have a Google login working and a Password/Email version working seperately, however they do not yet work together on the same account. For example I want to allow a user to log into his account with his google account or his username and password - both using the same credential token. I am using firebase as the backend. I was hoping someone knew of a good example i could follow or if someone knew the code i needed to make the connection and where to place it on a standard log in application on Android, Many thanks !!

Upvotes: 2

Views: 1038

Answers (2)

Michele La Ferla
Michele La Ferla

Reputation: 6884

All you need to do is the following:

AuthCredential credential = GoogleAuthProvider.getCredential(googleIdToken, null);
mAuth.getCurrentUser().linkWithCredential(credential)
    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            task.isSuccessful());

            if (!task.isSuccessful()) {
                Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
                        Toast.LENGTH_SHORT).show();
            }
        }
    });

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317467

I think the official documentation you're looking for is under the heading "Link Multiple Auth Providers".

Upvotes: 0

Related Questions