diff --git a/openseadragon.module b/openseadragon.module index 161e42d..caff59b 100644 --- a/openseadragon.module +++ b/openseadragon.module @@ -89,6 +89,7 @@ function template_preprocess_openseadragon_formatter(&$variables) { $variables['#attached']['library'] = [ 'openseadragon/init', ]; + $access_token = \Drupal::service('jwt.authentication.jwt')->generateToken(); $variables['#attached']['drupalSettings']['openseadragon'][$openseadragon_viewer_id] = [ 'basePath' => Url::fromUri($iiif_address), 'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'], @@ -110,11 +111,12 @@ function template_preprocess_openseadragon_formatter(&$variables) { * Implements template_preprocess_HOOK(). */ function template_preprocess_openseadragon_iiif_manifest_block(&$variables) { + $access_token = \Drupal::service('jwt.authentication.jwt')->generateToken(); $cache_meta = CacheableMetadata::createFromRenderArray($variables); // Get the tile sources from the manifest. $parser = \Drupal::service('openseadragon.manifest_parser'); - $tile_sources = $parser->getTileSources($variables['iiif_manifest_url']); + $tile_sources = $parser->getTileSources($variables['iiif_manifest_url'], $access_token); if (empty($tile_sources)) { $cache_meta->applyTo($variables); diff --git a/src/IIIFManifestParser.php b/src/IIIFManifestParser.php index fc98f6a..e837b13 100644 --- a/src/IIIFManifestParser.php +++ b/src/IIIFManifestParser.php @@ -64,11 +64,13 @@ public function __construct( * * @param string $manifest_url * The location of the IIIF manifest, which can include tokens. + * @param string $access_token + * The JWT Access token. * * @return array * The URLs of all the tile sources in a manifest. */ - public function getTileSources($manifest_url) { + public function getTileSources($manifest_url, $access_token = NULL) { // Try to construct the URL out of a tokenized string // if the node is available. @@ -85,7 +87,11 @@ public function getTileSources($manifest_url) { try { // Request the manifest. - $manifest_response = $this->httpClient->get($manifest_url); + $manifest_response = $this->httpClient->request('GET', $manifest_url, [ + 'headers' => [ + 'Authorization' => 'Bearer ' . $access_token, + ], + ]); // Decode the manifest json. $manifest_string = (string) $manifest_response->getBody();