Search code examples
javaspring-bootfirebasefirebase-authentication

Spring Boot FirebaseAuth signInWithEmailAndPassword method undefined for (String, String)


I am trying to simply verify if the correct password was entered for a Firebase User given email and password. I assumed the easiest way to do this would just be signing in (if there is another way please let me know and I will try it).

I am able to access the project as well as user details such as uid with this code:

FirebaseAuth mAuth = FirebaseAuth.getInstance();
UserRecord test = mAuth.getUserByEmail(email);

However when I try to put

mAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener...

I get the error message "The method signInWithEmailAndPassword(String, String) is undefined for the type FirebaseAuthJava(67108964)"

According to the docs this method should be valid.

I have these imports

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions; 
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.UserRecord;

This is the only dependency I have in my pom.xml for firebase

     <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>6.2.0</version>
     </dependency>

Please let me know if there is an error somewhere or if I need an additional dependecy/import to get this sign in to work

EDIT I realize that I cannot use firebase admin for this purpose, however is there another SDK I might be able to use to fulfill my goal?


Solution

  • You're importing the Firebase Admin SDK, which is designed to be used in trusted environments and runs as an administrative user. This SDK does not have a concept of a current user, and thus has no methods to sign in a user.

    I'm not sure why you feel the needs to validate the credentials on your own server, as normally you'd pass the ID token from the client to the server, verify the ID token there, and base your server-side logic based on the claims in that. If you really have to validate the credentials, you can call the REST API to sign in the user.