Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax headers in viewer don't get propagated to navigator #2502

Open
mariokolenic opened this issue Mar 28, 2024 · 3 comments
Open

Ajax headers in viewer don't get propagated to navigator #2502

mariokolenic opened this issue Mar 28, 2024 · 3 comments
Labels

Comments

@mariokolenic
Copy link

Could someone please advise me how to add an Authorization token to the NAVIGATOR request header when using TileSource (via URL) ?
Currently I have added the authorization token only for the Viewer, which unfortunately does not forward it to the navigator and its requests.

My code looks like this for now:

this.viewer = new OpenSeadragon.Viewer({
      element: container,
      showNavigationControl: false,

      showNavigator: true,
      navigatorId: 'navigatorDiv',
      navigatorDisplayRegionColor: '#f9df57',

      ajaxHeaders: {
        Authorization: `Bearer ${localStorage.getItem('access_token')}`,
      },
      loadTilesWithAjax: true,

      tileSources: {
        height: this.sampleImageMetadata!.size.height.pixel,
        width: this.sampleImageMetadata!.size.width.pixel,
        tileSize: this.sampleImageMetadata!.tile.optimal.width,
        minLevel: 1,
        maxLevel: this.sampleImageMetadata!.levels,
        getTileUrl: (level, x, y) => this.fetchTileUrl(level, x, y),
      },
    });

What I figured out is that the viewer has ajaxHeader set, but the navigator doesn't - here's the console output:
Snímka obrazovky 2024-03-28 o 15 06 33

Snímka obrazovky 2024-03-28 o 15 06 58

Can anyone please help me how I can get that authorization to the navigator as well ?

@mariokolenic mariokolenic changed the title Question: OpenSeaDragon in Angular 21 - using TileSources via URL using Authorization Token in request header Question: OpenSeaDragon in Angular 21 - TileSources via URL with Authorization Token in request header Mar 28, 2024
@iangilman
Copy link
Member

iangilman commented Mar 28, 2024

Wow, that looks like a bug! To fix it, we will need to pass loadTilesWithAjax and ajaxHeaders through when creating the navigator here:

this.navigator = new $.Navigator({

... And probably also call setAjaxHeaders on the navigator in here:

setAjaxHeaders: function(ajaxHeaders, propagate) {

Possibly there are other ajax-related properties that should be propagated?

You're welcome to make a PR if you'd like!

Otherwise, you could probably work around it like so:

viewer.navigator.loadTilesWithAjax = true;

viewer.navigator.setAjaxHeaders({
     Authorization: `Bearer ${localStorage.getItem('access_token')}`,
});

@iangilman iangilman added the bug label Mar 28, 2024
@iangilman iangilman changed the title Question: OpenSeaDragon in Angular 21 - TileSources via URL with Authorization Token in request header Ajax headers in viewer don't get propogated to navigator Mar 28, 2024
@iangilman iangilman changed the title Ajax headers in viewer don't get propogated to navigator Ajax headers in viewer don't get propagated to navigator Mar 28, 2024
@mariokolenic
Copy link
Author

Thank you, I have ingested the current alternative solution. If I have time in the later future, I'll add a PR to the fix as well.

When using the alternative, I found that there are no TYPES created for angular TS on the mentioned functions. So the second problem is that I need to write for the developers of TYPES for OSD - @types/openseadragon, that they don't have access to multiple functionalities.

@iangilman
Copy link
Member

The Navigator is basically a subclass of Viewer which is where those functions come from. Do the types reflect that? One option might be to do a viewer.navigator as Viewer to get proper access. But of course it would be good if the types reflected that properly. I'm sure you're welcome to make a PR over at that repository if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants