How to Use an Updated Access Token in Content Explorer
AnsweredHello, I am using the non-React version of Content Explorer, as documented here: https://developer.box.com/docs/box-content-explorer#section-sample-html.
Everything is working great. As expected, the access token expires after about 60 minutes. I have a separate service that is able to get a new access token in the background. However, I cannot figure out how to update the Content Explorer instance with this new token. Calling contentExplorer.show() with the new token doesn't seem to work. I feel like I'm missing something super obvious. Thanks.
-
thanks for the suggestion. Removing the container and reinitializing the explorer works, but it's undesirable for 2 reasons:
- there is a visual flicker
- the navigation hierarchy is reset to the top level
Is there really no way to update the token in place? This must be a common scenario, no? I'm browsing some files, I step away for lunch, I come back, bam - I get an error when I try to resume browsing.
I did find these issues (#640, #641), which ask the same question for Content Preview. I don't quite understand the final comment: "We decided to keep the interface for box-content-preview and make modifications to the interface at a higher level in box-ui-elements." It's referring to an undocumented updateToken method on Content Preview.
-
Hi :
The token value is passed to our API factory when ContentExplorer is instantiated; we currently don't provide a mechanism to update it afterward. However, rather than passing a token string, you could instead pass a function that returns a promise that resolves to a token string:
const contentExplorer = new ContentExplorer(); const tokenGenerator = function() { // Whatever logic is needed, so long as it returns a promise which ultimately resolves with a token string }; contentExplorer.show(FOLDER_ID, tokenGenerator);
You can find related documentation for the same concept in our box-content-preview library. Hope that helps.
Please sign in to leave a comment.
Comments
4 comments