0

I'm working using OAuth 2.0 to authenticate to a Google's API and everything works just fine in my local GlassFish. The problem begins when I'm deploying to the DEV's GlassFish, which throws me the following exception:

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request { "error" : "invalid_grant" }

This is my code:

        transport = GoogleNetHttpTransport.newTrustedTransport();
        jsonFactory = JacksonFactory.getDefaultInstance();

        credential = new GoogleCredential.Builder()
                .setTransport(transport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountUser(googleAdminEmail)
                .setServiceAccountId(googleAdminAccount)
                .setServiceAccountScopes(Arrays.asList(
                                DirectoryScopes.ADMIN_DIRECTORY_USER,
                                DirectoryScopes.ADMIN_DIRECTORY_GROUP,
                                DirectoryScopes.ADMIN_DIRECTORY_GROUP_MEMBER))
                .setServiceAccountPrivateKeyFromP12File(new File(googleAdminKeyPath))
                .build();           

        credential.refreshToken();

The exact line that throws me the exception is:

 credential.refreshToken();

If I get the Access Token from my local run, let's say the token value is "usghiudblk", and I set that value when running on DEV's GlasshFish: credential.setAcessToken("usghiudblk"); it will let me access normally but still this won't work: credential.refreshToken();

I truly can't tell why everything works just fine in local but doesn't works in DEV's GlassFish.

abraham
  • 46,583
  • 10
  • 100
  • 152
luisen
  • 157
  • 2
  • 9

1 Answers1

0

Solved it by the answer on this post:

Invalid grant when accessing Google API

The problem was that the server's clock was not synchronized with NTP.

That was it...

Community
  • 1
  • 1
luisen
  • 157
  • 2
  • 9