Skip to main content
PunchPlay’s JSON field names are stable and map directly onto Retrofit and kotlinx.serialization. A TV or mobile client authenticates with the device flow, then mirrors the library through partner sync.

Keeping the token fresh

Access tokens last one hour, so refresh is not optional — a client that only stores the access token stops working mid-session. Refresh tokens last a year but rotate on every use: each refresh returns a new one and immediately invalidates the old. That rotation is the part worth care on Android. Several coroutines hitting the API at once will each see 401 and each try to refresh, and those refreshes invalidate one another — signing the user out. Serialise them behind a mutex so only the first refreshes and the rest await its result:
Retry a 401 exactly once. If the replay also fails, the refresh token is gone and the profile must run device authorization again. Recommended initial-sync ordering:
Applying a change twice must be harmless: delivery is at-least-once, so applyChangeOrTombstone should key on resource plus resourceId rather than assume each change arrives once. Use one encrypted token record and one sync cursor per Nuvio profile. Never share an access token or cached mirror between profiles.