As per here after you generate an authentication token, it's valid for 15 minutes before it expires.
Consequently, if you don't hold onto the connection it will expire after 15 mins.
Upon application startup, we have code a bit like this:
Jdbi.create(dbProperties().getDbUrl(), jdbiProperties());
part of the jdbiProperties()
method calls:
generator.getAuthToken(GetIamAuthTokenRequest.builder()
.hostname(url).port(PORT).userName(username)
.build());
We have a repo method that uses the jdbi (wrappper of a JDBC DataSource) like so:
jdbi.withHandle(handle ->
handle.createQuery("select name from contacts")
.mapTo(String.class)
.list());
The problem here is that since we generated the token upon startup it stop working after 15 min.
Is the some standard pattern for dealing with this? Seems like we could refresh the token upon every call (seems inefficient). Or we could request a new token upon receipt of expiry (through an exception).
Any suggestions appreciated.
TIA