我正在使用适用于 Java的Google API 客户端库来检索访问令牌。
代码:
public static String getAccessToken() throws IOException {
GoogleCredential googleCredential = GoogleCredential
.fromStream(new FileInputStream(PATH_JSON_AUTH02))
.createScoped(Arrays.asList(URL_SCOPE_FCM));
googleCredential.refreshToken();
return googleCredential.getAccessToken();
}
问题是 JVM 找不到可信证书来向 Google 服务发出 HTTPS 请求。我尝试使用 keytool 导入所有类型的 Google 证书,但仍然无法正常工作。
例外:
10:03:29,371 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/TesteCertificadoGoogle].[tudo.ApplicationService]] (http--0.0.0.0-8443-2) Servlet.service() for servlet tudo.ApplicationService threw exception: org.jboss.resteasy.spi.UnhandledException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我应该导入哪个证书?
应该不需要从那里导入证书。我做了一个检查和用于访问 URL 的证书:https : //accounts.google.com/o/oauth2/auth 默认情况下已经存在于 Java 信任存储 (cacerts) 中。确保您使用的是默认的 Java 信任存储(cacerts)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句