0

I recently deployed a Spring Boot app to Elastic Beanstalk. Spring starts with no errors.

We are using Firebase for user authentication. On a local machiene or even on other external hosts the Firebase operations worked all fine, but not on EBS.

If i read the logs:

java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:164) ~[firebase-admin-6.3.0.jar!/:na]
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:135) ~[firebase-admin-6.3.0.jar!/:na]
at com.google.firebase.auth.FirebaseAuth.getInstance(FirebaseAuth.java:100) ~[firebase-admin-6.3.0.jar!/:na]
at com.bodymate.springend.mvc.service.FirebaseService.validateToken(FirebaseService.java:15) ~[classes!/:1.0-SNAPSHOT]
at com.bodymate.springend.mvc.controller.UserController.register(UserController.java:66) ~[classes!/:1.0-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]...

This is my firebase config:

@Configuration
public class FirebaseConfig {

@PostConstruct
public void init() {

    FirebaseOptions options;

    try {

        FileInputStream serviceAccount = new FileInputStream("src/main/resources/google-services.json");
        options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                .build();

    } catch (java.io.IOException e) {
        e.printStackTrace();
        return;
    }

    FirebaseApp.initializeApp(options);
}
}

The point where it gets out of hand:

@Service
public class FirebaseService {

public FirebaseToken validateToken(String token) throws InterruptedException, ExecutionException, InvalidFirebaseTokenException {

    FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdTokenAsync(token).get();

    if( decodedToken != null && decodedToken.getUid() != null && !decodedToken.getUid().isEmpty()){
        return decodedToken;
    }else{
        throw new InvalidFirebaseTokenException();
    }
}
}

Does someone has any idea what is going wrong here ?

EDIT

I am using mvn clean install to build my .jar file for EBS. Is it possible that this build does not contain the "google-services.json" ?

Palm
  • 699
  • 1
  • 6
  • 17
  • Possible duplicate of [FirebaseApp with name \[DEFAULT\] doesn't exist](https://stackoverflow.com/questions/37342403/firebaseapp-with-name-default-doesnt-exist) – Martin Zeitler Aug 21 '18 at 15:42
  • in this case, it might not have the `google-services.json` loaded (just alike the possible dupe I've just referenced)... therefore it will fall-back to project_id `DEFAULT`. – Martin Zeitler Aug 21 '18 at 15:44
  • @MartinZeitler Yes, I saw that. So how can this work on other hosts but not on EBS ? – Palm Aug 21 '18 at 15:47

0 Answers0