I have a Java Rest API running with Jersey on a Glassfish server, and I use Firebase Auth to authenticate my users.
So I use the Firebase Admin SDK to verify the token FirebaseAuth.getInstance().verifyIdToken(idToken)
But it throws the following error:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I initialize my app correctly, by calling:
FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccountStream)).build();
With serviceAccountStream an InputStream to my service account JSON file.
Edit: I got the same problem with Firebase's auth emulator and other Firebase services such as Firestore, that's weird
The problem is coming from the old libraries you use. The following code works fine on SpringBoot 2.5 set up:
try {
InputStream serviceAccount credStream = getClass().getResourceAsStream(credsPath);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(credStream))
.setDatabaseUrl(databaseURL)
.build();
FirebaseApp.initializeApp(options);
} catch (Exception e) {
logger.error(e.getMessage());
} finally {
...
}
If you cannot upgrade the libraries, you need to add your server certificate into the trustStore. Please, look here for the steps: Java: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With