Bearer Token refresh for 3dTiles/ImageryProviders

I have a token that I pass to a resource header to create some 3dTiles. However, the token expires and requires a new token every so often. I used retryCallback to essentially get a new token based on the Cesium.Resource documentation. It somewhat works, but there also seem to be lingering requests using the old expired token, almost in parallel. Is there some sort of clean up or handling that I need to perform after the retryCallback to refresh token?

Thanks

I did some more digging and noticed a similar behavior with WmtsProviders. For example, I created some view models using WmtsProviders and Resource that contains there token in the headers.

function generateResource(url) {
  return new Cesium.Resource({
    url: url,
    headers: {
      Authorization: `Bearer ${authService.getToken()}`;
    },
    retryCallback: (res, err) => {
      if (err && err.statusCode === 403) {
        // authService already refreshed token app-side, so not async
        res.headers.Authorization = `Bearer ${authService.getToken()}`;
        return true;
      }

      return false;
    },
    retryAttempts: 2,
  })
}

function generateViewModel(name, url) {
  return new Cesium.ProviderViewModel({
    name: name,
    tooltip: name,
    createFunction: () => {
      const wmts = new Cesium.WebMapServiceImageryProvider({
        url: generateResource(url),
        layer: name,
        format: 'image/png',
        style: 'raster',
        tileMatrixSetID: 'EPSG:4326',
      });

      viewer.imageryLayers.addImageryProvider(wmts);
      
      return wmts;
    }
  })
}

const newViewModel= generateViewModel('MyViewModel', wmtsService.getUrl());

viewer.baseLayerPicker.viewModel.imageryProviderViewModels.unshift(newViewModel);
viewer.baseLayerPicker.viewModel.selectedImagery = newViewModel;

This works but noticed that the original request (with old token) continues to make the request, fails, retries, success. This causes the console to be spammed with 403s. I’ve also tried to set the selectedImagery to an updated viewModel, but that wipes the cached data on every token refresh.

Wondering if the team have some insight. Thanks.

Hi @tluong,
Thanks for your post and welcome to the Cesium community.
Noting on this thread that we have an open issue for this topic, which you already found and commented on: Cesium Resource retryCallback update queryParameters or header only valid in current request · Issue #10435 · CesiumGS/cesium · GitHub
Please feel free to add additional comments here or on the GitHub issue.
We hope to get this resolved shortly.
Thanks,
Luke