Hey folks.
We’ve got a C# service using the Genesys Cloud .NET SDK. It works fine for a while, then suddenly all API calls start throwing 401 Unauthorized. The logs show the refresh token flow triggers, a new access token is obtained, but the next request still fails with 401.
I’m thinking clock skew between our Azure Function host and the Genesys Cloud auth server. Our server time is synced, but maybe the token expiration calculation is off by a few seconds?
Here’s the relevant snippet from our token refresh handler:
var client = new Client("https://api.mypurecloud.com");
var request = new Request("/oauth/token", Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "refresh_token");
request.AddParameter("refresh_token", refreshToken);
request.AddParameter("client_id", clientId);
request.AddParameter("client_secret", clientSecret);
var response = await client.ExecuteTaskAsync(request);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception($"Refresh failed: {response.Content}");
}
var tokenData = JsonConvert.DeserializeObject<TokenResponse>(response.Content);
// Save new tokens...
The response.StatusCode is 200, and the new token looks valid in the JSON payload. I even decoded the JWT and the exp claim is in the future. But when I use the new access token in the next API call (e.g., GET /api/v2/users/me), it returns 401.
Is there a known issue with the .NET SDK handling token refresh timing? Or should I manually add a buffer to the expiration time before attempting the refresh? We’re using version 3.2.1 of the SDK.
Any help is appreciated.