0

I was trying to initialize the Admin SDK, but facing 400 bad request in service account initialization. It was working perfectly in my development windows environment, but when I deploy the same in linux, am facing this issue.

        SpringApplication.run(OrderApplication.class, args);

        FileInputStream serviceAccount = new FileInputStream(GlobalValue.serviceAccount);

        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                .setDatabaseUrl("https://xxxxxxx.firebaseio.com").build();

        FirebaseApp.initializeApp(options);

    }

I am reading the file path from property file.

service.account=/home/service-account.json

I was trying to send push notification, am facing issue at that time.


        try {
            MulticastMessage multicastMessage = MulticastMessage.builder().addAllTokens(lDeviceTokens)
                    .setNotification(new Notification(title, message)).build();

            BatchResponse response = FirebaseMessaging.getInstance().sendMulticast(multicastMessage);
            // See the BatchResponse reference documentation // for the contents of
            // response.
            System.out.println(response.getSuccessCount() + " messages were sent successfully");
        } catch (FirebaseMessagingException e) {
            e.printStackTrace();
            System.out.println(e.getLocalizedMessage());
        }
    }

Trace

. java: 141 S)
at org . apache . tomcat . util .neC . Socket ProcessorBase . run (Socket ProcessorBas
e . java : 49)
at java . concurrent . ThreadPooIExecuCor . runWorker (ThreadPooIExecuC01 .
java : 1149)
at java . concurrent . ThreadPooIExecucor$Worker . run (ThreadPooIExecuC01
. java : 624)
at org . apache . ComcaC . util . Chreads . TaskThread$WrappingRunnabIe . run (TaskTh
read . java : 61)
at java. lang . Thread. run (Thread. java : 7 48)
Caused by: java.io. IOExcepCion: Error getting access token for service account :
400 Bad Request
"error" • "invalid grant"
"error description" • "Invalid JWT: Token must be a short—lived token (60 minut
es) and in a reasonable timeframe. Check Y2ur iat and exp values and use a clock
with skew to account for clock differences between systems . "
at com.google . auth . oauCh2 . ServiceAccounCCredenCiaIs . refreshAccessToken ( S
erviceAccounCCredenCiaIs . java : 401)
at com.google . auth . oauCh2 . OAuth2CredenCiaIs . refresh (OAuth2CredenCiaIs . j a
va:181)
at com.google . auth . oauCh2 . OAuth2CredenCiaIs . geCRequesCMeCadaCa (OAuth2Cre
dentials . java : 167)
Jay Vignesh
  • 374
  • 3
  • 11

1 Answers1

0

Please see these links if they help, looks to be a server time issue as you move to linux

Google Client Invalid JWT: Token must be a short-lived token

Token must be a short-lived token and in a reasonable timeframe

TechFree
  • 2,600
  • 1
  • 17
  • 18