gpt4 book ai didi

java - 使用 Firebase 时出现 SunCertPathBuilderException

转载 作者:行者123 更新时间:2023-12-04 17:15:44 26 4
gpt4 key购买 nike

我有一个在 Glassfish 服务器上与 Jersey 一起运行的 Java Rest API,我使用 Firebase Auth 来验证我的用户。所以我使用 Firebase Admin SDK 来验证 token FirebaseAuth.getInstance().verifyIdToken(idToken)

但它抛出以下错误:

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

我通过调用正确地初始化了我的应用程序:

FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccountStream)).build();

使用 serviceAccountStream 将 InputStream 发送到我的服务帐户 JSON 文件。

编辑:我在使用 Firebase 的身份验证模拟器和其他 Firebase 服务(例如 Firestore)时遇到了同样的问题,这很奇怪

最佳答案

问题出在您使用的旧库中。以下代码在 SpringBoot 2.5 设置上运行良好:

    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 {
...
}

如果您无法升级库,则需要将您的服务器证书添加到信任库中。请在此处查找步骤:Java: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

关于java - 使用 Firebase 时出现 SunCertPathBuilderException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68776047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com