Firebase ID 令牌验证 - Java NoSuchMethod

Firebase ID Token verification - Java NoSuchMethod


我尝试使用 Firebase Admin SDK 在 Netbeans 中创建一个简单的服务器。我尝试在服务器上验证 ID 令牌,但我得到了一个 错误

Exception in thread "pool-1-thread-2" java.lang.NoSuchMethodError: com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getServiceAccountProjectId()Ljava/lang/String;
at com.google.firebase.auth.FirebaseAuth.then(FirebaseAuth.java:157)
at com.google.firebase.auth.FirebaseAuth.then(FirebaseAuth.java:152)
at com.google.firebase.tasks.ContinueWithCompletionListener.run(ContinueWithCompletionListener.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

这是代码

public static void main(String[] args) throws FileNotFoundException {
    FileInputStream serviceAccount = new FileInputStream("E:\Letöltések\...");

    FirebaseOptions options = new FirebaseOptions.Builder()
            .setServiceAccount(serviceAccount)
      .setDatabaseUrl("https://... .firebaseio.com")
      .build();

    FirebaseApp defaultApp = FirebaseApp.initializeApp(options);
    System.out.println(defaultApp.getName());

    FirebaseAuth defaultAuth = FirebaseAuth.getInstance(defaultApp);
    FirebaseDatabase defaultDatabase = FirebaseDatabase.getInstance(defaultApp);

    String idToken = getIdToken(); //"eyJhb..."

    FirebaseAuth.getInstance().verifyIdToken(idToken)
    .addOnSuccessListener(new OnSuccessListener<FirebaseToken>() {
            @Override
            public void onSuccess(FirebaseToken decodedToken) {
                String uid = decodedToken.getUid();
                System.out.println("UID: " + uid);
            }
    });
}

Firebase Admin Node.js SDK 的最新 4.1.0 版本中存在错误(在我们的发行说明 here 中注明)。要解决此问题,您可以降级到版本 4.0.4。我们将在本周早些时候推出一个新版本来解决这个问题。抱歉,有任何问题!