获取访问令牌时出现证书错误
Certificate error while getting access token
我正在使用 Google API Client Library for Java 检索访问令牌。
代码:
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)
我正在使用 Google API Client Library for Java 检索访问令牌。
代码:
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)