admin管理员组文章数量:1125886
I am encountering the following exception when sending push notifications (both token-based and topic-based) using Firebase in my Java Play Framework application on the development server:
Caused by: java.io.IOException: Error getting access token for service account:
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:395)
at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:179)
at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:165)
at com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:96)
at com.google.firebase.internal.FirebaseRequestInitializer.initialize(FirebaseRequestInitializer.java:55)
at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:93)
at com.google.api.client.http.HttpRequestFactory.buildPostRequest(HttpRequestFactory.java:133)
at com.google.firebase.messaging.FirebaseMessagingClientImpl.sendSingleRequest(FirebaseMessagingClientImpl.java:147)
at com.google.firebase.messaging.FirebaseMessagingClientImpl.send(FirebaseMessagingClientImpl.java:125)
... 13 more
Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
{"error":"invalid_grant","error_description":"Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim."}
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1072)
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:393)
... 21 more
This issue occurs only when the application is deployed on the development server and does not happen locally.
I have done the below checks/fixes :
Verified the service account credentials JSON file is accessible on the dev server.
Checked that the environment variables are set correctly.
Confirmed that the dev server has proper network access to Firebase services.
Synchronized the server time (since the error mentions issues with token expiration), note that it is hosted in Singapore.
Ensured that the service account has sufficient permissions to send notifications.
Server details :
Dev Server Environment: Bare-metal monolithic deployment (not using Docker or containerized environments), hosted in Singapore.
Firebase SDK Version: firebase-admin 6.8.1
Java Version: 8
Play Framework Version: 1.0-SNAPSHOT
I am using the following method to send push notifications, which works locally but fails on the dev server :
@Override
public void sendNotificationByTopic(String topic, String title, String body) {
ExecutorManager.getExecutorService().execute(()-> {
try {
// create the message for the topic
Message message = Message.builder()
.putData("title", title)
.putData("body", body)
.setTopic(topic)
.build();
// send the push notification
try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseException e) {
LOGGER.info("Encountered an exception while sending push notification for the topic");
}
} catch (Exception e) {
throw new FirebaseMessageException("Encountered a generic exception in sendNotificationByTopic");
}
});
}
What could be causing the java.io.IOException
related to the access token, and why does this issue occur only on the development server? How can I resolve this, considering the configurations are correct on the dev server?
本文标签:
版权声明:本文标题:Firebase Push Notifications Failing on Dev Server: java.io.IOException Access Token Error in Java - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736668846a1946805.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论