Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Getting Oath 2 access token issue

Hi, 

We are fetching data from Big Query using Spring Boot and doing some processing in that data which is taking around 1-1.5 hours and after the process completes, we again have to hit the bigquery to fetch some more records but in between only we are getting 
Exception in thread "Thread-38" com.google.cloud.bigquery.BigQueryException: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.

We are using the below approach to create the credential using the Access Token and providing the token expiry time as 2 hours.

Date oldDate = new Date(); 
Date newDate = new Date(oldDate.getTime() + TimeUnit.HOURS.toMillis(2));
Credentials credentials2 = GoogleCredentials.create(new AccessToken(token, newDate));

We have tried increasing the expiry time to 3 and 4 hours also but it is still failing with the same error.

When I checked the documentation to find from which method is throwing this issue, I found OAuth2Credentials class which has a method refreshAcessToken and this method is throwing that issue. OAuth2Credentials class is extending the Credentials class, still not able to find from where this error is coming as we are not using OAuth2Credentials 

One more fix I tried was creating OAuth2Credentials object reference instead of Credentials and overriding the refreshAccessToken method to provide my own implementation to refresh the Access token but that one is also not working. 
Can anyone please help me on this issue?

Could anyone help on this issue. What will be the more feasible way to approach this issue.

0 6 1,566
6 REPLIES 6