Hi All
To start with some (hopefully helpful) context, I'm developing for a client that has a presence in multiple regions and in some of those regions, they have multiple organizations.
We're building a single application using the SDK to handle day to day operations such as user creation (along with phones, assigning skills, groups, etc) and also reporting.
So to the problem:
I create an instance of the ApiClient and assign it things like the region, proxy, retryConfig, clientId, clientSecret, etc.
// Sets proxy
var configOptions = new ApiClient.ClientRestOptions(){
Proxy = new WebProxy(config.proxy, false, config.proxyBypassList.ToArray(), CredentialCache.DefaultCredentials)
};
// Sets automatic retries
var retryConfig = new ApiClient.RetryConfiguration{
MaxRetryTimeSec = 10,
RetryMax = 5
};
We iterate over our list of environments and instantiate a new ApiClient for each environment using those options as well as assign the clientId and clientSecret.
Now I want to make an API call, lets use UsersApi for this example.
So we instantiate the UsersApi and pass a Configuration object which contains our ApiClient.
Configuration configuration = new Configuration(apiClient);
UsersApi.Configuration = configuration;
At this point we still don't have an access token so we call
UsersApi.Configuration.ApiClient.PostToken(clientId, clientSecret);
The access token gets stored in UsersApi.Configuration.ApiClient.Configuration.AccessToken
The problem with this is that the UsersApi looks for that access token in UsersApi.Configuration.AccessToken, so we get a 401 ApiException with 'no authentication bearer token specified in authorization header'. So the UsersApi does read the region and proxy settings specified in the ApiClient, just not the access token.
Ok, so we can code upfront to assign the access token from PostToken() to that field, but that only works once, in our case on app startup. When that token expires, our app should (in theory) break, unless we handle the ApiException.
BUT, ApiClient contains two functions that appear to be making the REST calls, CallApi and CallApiAsync - both of which checks for a 401 response and if so, calls function HandleExpiredAccessToken() to renew the token transparently in the background. Yet because it ultimately calls the same original function, PostToken, in ApiClient to renew that access token, it will never be stored in the correct UserApi.Configuration.AccessToken field, and calls will continue to return a 401.
Am I misunderstanding how the ApiClient works when used within the context of the UsersApi? Any advice or suggestions are appreciated!