box / box/box-content-preview

refreshing expired tokens

Open
#640 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
120
Forks
137
Avg merge
12h 36m
Merged PRs (30d)
17

Description

Downscoped tokens only live for about an hour.

So when viewing a long video — especially if you pause it for a while and come back later — the viewer stops with an error message, and the `load` event handler is sent an error like this:

> `Shaka error. Code = 1001, Category = 1, Severity = 2, Data = https://public.boxcloud.com/api/2.0/internal_files/269427057885/versions/283639980141/representations/dash/content/audio/0/292.m4s?access_token=1!big...Long...token&box_client_name=box-content-preview&box_client_version=1.24.0,401,,[object Object]`

when Shaka's request for that next audio or video segment is denied with a 401 response.

(The players for other document types may have similar issues, but video is the one we're running into this issue with on a daily basis.)

To address this we need a few things:

1. Know when it's time to replace the token, by
a. detecting a "token expired" failure response when it happens, or
b. learning up-front what the token's lifetime is when it's first provided to the Preview, or
c. given a token, use some Box "tell me about this token" API to determine its expiration time.
2. Have some way to update the token used by the Preview.
* Turns out this already exists! Preview has an `updateToken` method. Also, `accessToken` may be a Promise-returning function, in which case it might not need to do `updateToken` at all, just re-get using the already provided generator.
* but that documentation isn't published anywhere, which I'll file under issue #641

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.