简体   繁体   中英

FirebaseAuth JAVA (Spring boot) verify token

Grettings. i'm implementing a Firebase auth for my mobile app with custom existing back-end (Spring Boot). I'm successfully authenticating in facebook by using firebase in mobile app => want to store user info at my back-end's DB (not firebase).

Stuck to debug the token verification error.

Token verification - almost same as in google doc:

   try {
        FirebaseToken decodedToken = Tasks.await(
                FirebaseAuth.getInstance().verifyIdToken(info.getToken()));
    } catch (ExecutionException | InterruptedException | IllegalArgumentException e) {
        logger.error(e.getMessage());
    }

getting an error: java.lang.IllegalArgumentException

and can't find out/debug what is causing it.

related - firebase config:

@Configuration
public class FirebaseConfig {

    private final static Logger logger = LogManager.getLogger(FirebaseConfig.class.getName());

    @Value("classpath:firebase_config.json")
    private Resource firebase_config;

    @PostConstruct
    public void init() throws IOException {

        FileInputStream serviceAccount = new FileInputStream(firebase_config.getFile());

        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
                .setDatabaseUrl("https://******-81233.firebaseio.com")
                .build();
        FirebaseApp.initializeApp(options);
        logger.info("Firebase init done");
    }
}

UPDATE: added:

FirebaseAuth.getInstance().verifyIdToken(info.getToken()).addOnFailureListener(e -> {
                    System.err.println("Error verifying token: " + e.getMessage());
                });

the error i getting is simply null which isn;t saying anything about it's origin.

Build release APK version. Deploy and try again. The hashes will be different so that it might help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM