google-cloud-java
google-cloud-java copied to clipboard
[translate v3, 2.17.0]: CredentialsProvider is called only once
Environment details
- OS type and version: Ubuntu 22.04
- Java version: 17
- Version(s): 2.17.0
Steps to reproduce
- Get a short lived oauth2 token
- Pass it to the
TranslateServiceClient - Call
translateTextonce - Wait for token to expire
- Call
translateTextanother time
Expected
getCredentials() is either called every time a request is made or an expired token error is received
Code example
class TokenBasedGoogleCredentialsProvider(val token: String)
) : CredentialsProvider {
override fun getCredentials(): Credentials {
return GoogleCredentials.create(token)
}
}
val credentials = TokenBasedGoogleCredentialsProvider("SOME_TOKEN_GENERATED_BY_OTHER_MEANS")
val translationServiceSettingsBuilder = TranslationServiceSettings.newBuilder()
translationServiceSettingsBuilder.setCredentialsProvider(credentialsProvider)
val client = TranslationServiceClient.create(translationServiceSettingsBuilder.build())
client.translateText("project/some-project", "cs", listOf("Hello"))
# Wait until token expires
client.translateText("project/some-project", "cs", listOf("Hello"))
Stack trace
Caused by: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata
at io.grpc.Status.asRuntimeException(Status.java:539)
... 14 common frames omitted
Caused by: java.lang.IllegalStateException: OAuth2Credentials instance does not support refreshing the access token. An instance with a new access token should be used, or a derived type that supports refreshing.
at com.google.auth.oauth2.OAuth2Credentials.refreshAccessToken(OAuth2Credentials.java:366)
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)
Also Storage and BigQuery clients seem to behave that way, so I have no issues with expiring tokens, because the provider refreshes it by other means instead of a refresh token.
@deejay1 Would you share your observation on Storage and BigQuery clients? (such as error messages)
Also Storage and BigQuery clients seem to behave that way
@deejay1 Can you provide some references to documentation that informed your expectation for when getCredentials() is supposed to be called?
cc: @TimurSadykov
Closing due to lack of updates from the OP.