Developing Live Experience (2024)

The JWT access token is only valid for a finite period of time.

Using an expired JWT will cause operations to fail. As you saw above, we are told how long a token is valid through expires_in. This value is normally 1200 seconds or 20 minutes. Expired tokens are not refreshed. We just fetch a new token and pass it to the Live Experience SDK.

You need to track the JWT expiration yourself. One way is to set a timer in your app to fetch a new token after 1200 seconds. Here is a timer in Swift:

Timer.scheduledTimer(timeInterval: expires, target: self, selector: #selector(fetchToken), userInfo: nil, repeats: false)

Another is to compute an expiration time by adding 1200 seconds to the current system time when the token was retrieved. So, if the time when you fetch the token was 10:00 the expiration time would be 10:20. An example of this in Swift looks like: let expireTime = Date().addingTimeInterval(expires).

You then compare the current time to the expiration time to see if the token has expired.

Twenty minutes is a long time and you may launch your app several times during that period. Storing your token in persistent storage allows it to survive after the app exits. Here is an example of storing a token and its expiration time in persistent storage with Swift:

UserDefaults.standard.set(token, forKey: "LXtoken")UserDefaults.standard.set(expireTime, forKey: "tokenExpireTime")
Developing Live Experience (2024)
Top Articles
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6385

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.