Rendering 3D tiles with a tileset url & accessToken

I would like to render my tileset using cesiumjs. The tileset url requires an access token to fetch the tileset.json file from the container.

In the past I have used code like this to render my tilesets:

const tilesetUrl = 'https://example.cloudfront.net/1234/tileset.json?sv=2024-05-04&spr=https&se=2024-11-09T23%3A59%3A59Z&sr=c&sp=rl&sig=<token>&Signature=<sig>';
const tileset = await Cesium3DTileset.fromUrl(tilesetUrl);
viewer.scene.primitives.add(tileset);

That works fine when the tilesetUrl does not require authentication. Can I use this same method to render a tileset Url which requires passing an accessToken as the Authorization header while fetching?

I figured it out! I needed to use the Resource object type instead of string type, which results in code like so:

await Cesium3DTileset.fromUrl(new Resource({
    url: tilesetUrl,
    headers: {
      'Authorization': `Bearer ${accessToken}`
    }}))

Figured I’d update this thread in case it helps anyone else in the future.

3 Likes