Error : Error getting access token for service account: Remote host terminated the handshake, iss

111 Views Asked by At

I'm using below Java snippet to get the Authentication token for Firebase Messaging. But its throwing error during refreshIfExpired method call.

Java code:

private static String getAccessToken() throws IOException {
    String[] SCOPES = {"https://www.googleapis.com/auth/firebase.messaging"};
    
    GoogleCredentials googleCredentials = GoogleCredentials.fromStream(new FileInputStream("./src/service-account.json")).createScoped(Arrays.asList(SCOPES));
    //googleCredentials.refresh();
    try {
        googleCredentials.getAuthenticationType();
        googleCredentials.refreshIfExpired();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    return googleCredentials.getAccessToken().getTokenValue();    
}

Cause: javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake.
Detailed Error: Error getting access token for service account: Remote host terminated the handshake, iss: firebase-adminsdk-jnf15@

Are these errors related to jars or certificates? As per Firebase documentation, they did not mentioned anything related to Certificates.

Java Snippet code from documentation link : https://firebase.google.com/docs/cloud-messaging/migrate-v1#use-credentials-to-mint-access-tokens

The getAccessToken() method was shared in Google Firebase API documentation and same was used by uploaded certain jars which are required.

This service supposed to return the Access Token which will be used in subsequent service as Bearer token to send the Notifications to devices in REST API call. But this service is not working as expected and returning error.

0

There are 0 best solutions below