Hi, everybody.
We are developing an application with several microservices. Invoking these microservices can include multiple calls to the Genesys API. We use client credentials grant authentication and set a exipry time of 300 seconds. I read in this post How to check token expiry? - #3 by tim.smith
"Also keep in mind that a well-formed application will never rely on the stated expiry time and will be able to gracefully handle a token expiring at any time for any reason."
We have implemented a strategy that when a com.mypurecloud.sdk.v2.ApiException occurs we catch it and if apiException.getStatusCode() == 401 we create a new instance of com.mypurecloud.sdk.v2.ApiClient by calling the setDefaultApiClient() method which is below:
public void setDefaultApiClient() {
ApiClient.Builder builder = ...
builder.withConnectionTimeout(...
builder.withBasePath(...
...
ApiClient apiClient = builder.build();
ApiResponse authResponse = apiClient.authorizeClientCredentials(clientId, clientSecret);
Configuration.setDefaultApiClient(apiClient);
}
Apart from the strategy explained in the previous lines to renew the token in case of a 401 error, and in order to make sure that we are never going to invoke an our application microservice with an expired token... can be considered a good practice to call the setDefaultApiClient() method every time an our application microservice is invoked? This could happen several times a second... or every 2 minutes... or every 10 minutes...
Thanks.