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

Adding JWT token to Openseadragon requests #40

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openseadragon.module
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ function template_preprocess_openseadragon_formatter(&$variables) {
'id' => $openseadragon_viewer_id,
'prefixUrl' => 'https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/images/',
'tileSources' => $tile_sources,
'loadTilesWithAjax' => TRUE,
'ajaxWithCredentials' => TRUE,
'ajaxHeaders' => ["Authorization" => "Bearer " . \Drupal::service('jwt.authentication.jwt')->generateToken()],
Copy link
Contributor

@adam-vessey adam-vessey Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache tags/contexts would have to be added for this to avoid using the results for all users and/or living beyond their expiry... and does it make sense to be generating tokens for anonymous users, if it's going to trash the cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @adam-vessey . I'll give it the caching treatment for users.

If anonymous having a token breaks caching, I can tell it not to add a token for anon and then adjust the custom delegate appropriately.

] + $viewer_settings,
];

Expand Down Expand Up @@ -124,6 +127,9 @@ function template_preprocess_openseadragon_iiif_manifest_block(&$variables) {
'id' => $openseadragon_viewer_id,
'prefixUrl' => 'https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/images/',
'tileSources' => $tile_sources,
'loadTilesWithAjax' => TRUE,
'ajaxWithCredentials' => TRUE,
'ajaxHeaders' => ["Authorization" => "Bearer " . \Drupal::service('jwt.authentication.jwt')->generateToken()],
] + $viewer_settings,
];

Expand Down