Skip to content

Latest commit

 

History

History
21 lines (13 loc) · 1.83 KB

access-tokens.md

File metadata and controls

21 lines (13 loc) · 1.83 KB

Access Tokens

The access token generated by your server component is a jwt that contains a grant for Programmable Voice, an identity that you specify, and a time-to-live that sets the lifetime of the generated access token. The default time-to-live is 1 hour and is configurable up to 24 hours using the Twilio helper libraries.

Uses

In the iOS SDK the access token is used for the following:

  1. To make an outgoing call via TwilioVoice.connect(...)
  2. To register or unregister for incoming notifications using VoIP Push Notifications via TwilioVoice.registerWithAccessToken(...) and TwilioVoice.unregisterWithAccessToken(...). Once registered, incoming notifications are handled via a TVOCallInvite where you can choose to accept or reject the invite. When accepting the call an access token is not required. Internally the TVOCallInvite has its own access token that ensures it can connect to our infrastructure.

Managing Expiry

As mentioned above, an access token will eventually expire. If an access token has expired, our infrastructure will return error TVOErrorAccessTokenExpired/20104 via TVOCallDelegate or a completion error when registering.

There are number of techniques you can use to ensure that access token expiry is managed accordingly:

  • Always fetch a new access token from your access token server before making an outbound call.
  • Retain the access token until getting a TVOErrorAccessTokenExpired/20104 error before fetching a new access token.
  • Retain the access token along with the timestamp of when it was requested so you can verify ahead of time whether the token has already expired based on the time-to-live being used by your server.
  • Prefetch the access token whenever the UIApplication, or UIViewController associated with an outgoing call is created.