Unable to Get or Refresh access token from Google Credentials instance in java sdk #2311
Labels
api: storage
Issues related to the googleapis/java-storage API.
type: question
Request for information or clarification. Not an issue.
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Hi There,
I am trying to getAccess Token from the GoogleCredentials object instance from java SDK. But getAccessToken() API returns null.
Also, the refreshIfExpired() API throws an exception. I have detailed it below.
I need access token to make an HTTP Request to initiate resumable and multipart uploads.
Reason to opt to ReST HTTP requests from java sdk is because of the following open issue with java sdk.
#2310 : Unable to initiate resumable uploads from java sdk: Cloud storage v2 API.
Here's the code:
`
Output:
`
credentials.getAccessToken(): null
Exception in thread "main" com.google.auth.oauth2.GoogleAuthException: Error getting access token for service account: 400 Bad Request
POST https://oauth2.googleapis.com/token
{"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}, iss: xxx@xx-development-xxxxxx.iam.gserviceaccount.com
at com.google.auth.oauth2.GoogleAuthException.createWithTokenEndpointResponseException(GoogleAuthException.java:129)
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:541)
at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:269)
at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:266)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at com.google.auth.oauth2.OAuth2Credentials$RefreshTask.run(OAuth2Credentials.java:633)
at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31)
at com.google.auth.oauth2.OAuth2Credentials$AsyncRefreshResult.executeIfNew(OAuth2Credentials.java:581)
at com.google.auth.oauth2.OAuth2Credentials.asyncFetch(OAuth2Credentials.java:232)
at com.google.auth.oauth2.OAuth2Credentials.refreshIfExpired(OAuth2Credentials.java:203)
at aone.libs.vault.GcsTest.main(GcsTest.java:54)
Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
POST https://oauth2.googleapis.com/token
{"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}
at com.google.api.client.http.HttpResponseException$Builder.build(HttpResponseException.java:293)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1118)
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:538)
... 9 more
Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
`
Appreciate any inputs, to help me proceed further.
Thanks in Advance,
Nithin
The text was updated successfully, but these errors were encountered: