✓ how_to (correct)
✓ medium (correct)
escalate: noSummary
Customer is building a custom Flex SDK integration and needs guidance on the correct token refresh flow, proactive expiry events, degraded mode recovery, and Voice Access Token TTL constraints to prevent session failures after the initial 3600s TTL.
Suggested first response
Hi Daniel,
Thank you for the detailed write-up — this gives us a clear picture of what you're working through. Let me address each of your questions:
1. **Token refresh sequence:** You are correct that fetching a new token on your backend and updating local state alone is not sufficient. You must call `client.updateToken(newToken, newRefreshToken)` on the Flex SDK client instance so that the underlying sub-clients (TaskRouter, Voice, Conversations, Sync) receive the updated credentials. Without this call, those clients continue using the stale token, which is consistent with the 45775 errors you are seeing. The general sequence is: (a) detect approaching expiry, (b) call your backend to mint a fresh token, (c) call `client.updateToken(newToken, newRefreshToken)`. The `validateToken` and `refreshToken` calls you referenced are server-side helpers for token validation/issuance and are not required steps in the client-side refresh flow itself.
2. **Proactive expiry event:** Yes, you should listen for a token expiry warning event on the client rather than reacting to failures. The Flex SDK surfaces a `tokenAboutToExpire` (or equivalent `tokenWillExpire`) event that fires before the token actually expires, giving you a window to fetch and apply a new token cleanly. We recommend triggering your refresh logic from this event rather than on a fixed timer or on error detection.
3. **Degraded mode and Voice recovery:** Your interpretation is correct. The `SessionState: setting degraded to true` log entry indicates that one or more sub-clients (in this case, the Voice SDK client) failed to reinitialize after the token became invalid — this is not a TaskRouter routing or Workflow configuration issue. Calling `client.updateToken(...)` with a valid fresh token should allow the SDK to attempt to recover the degraded sub-clients. However, if the Voice client has fully disconnected, a full client reinitialization may be required in some cases. We'd recommend testing the `updateToken` path first and observing whether the Voice client transitions out of degraded state.
4. **Voice Access Token vs. Flex JWE token:** These are two distinct token types with independent TTLs. The Flex user token (JWE) governs the Flex SDK session, while the Voice Access Token (a JWT you generate with your API key and secret, scoped to the Voice grant) governs the Voice SDK client. Error 31207 means the TTL you set on the Voice Access Token exceeds the maximum allowed value (3600 seconds for Voice Access Tokens). Ensure you are generating the Voice Access Token with a TTL of 3600 seconds or less, and refresh it independently of the Flex token on the same proactive schedule.
We'd recommend implementing the `tokenAboutToExpire` listener as your primary refresh trigger and confirming that `client.updateToken(...)` is called in all refresh paths before going to production. If after implementing these changes you continue to see 45775 errors or the Voice client does not recover from degraded state after a token update, please share a HAR file or console log from a reproduction session and we can dig deeper.
Best regards,
Twilio Support
1883 output tokens · 47.8s · 2 attempt(s)