From bf9fdca48cfc8ff22d9e7aa35a18934488f48aaa Mon Sep 17 00:00:00 2001 From: Kyle Huynh <7862086+kylehuynh205@users.noreply.github.com> Date: Thu, 6 Jul 2023 15:51:39 -0400 Subject: [PATCH 1/3] Update IIIFManifestParser.php --- src/IIIFManifestParser.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/IIIFManifestParser.php b/src/IIIFManifestParser.php index fc98f6a..8bbaca8 100644 --- a/src/IIIFManifestParser.php +++ b/src/IIIFManifestParser.php @@ -68,7 +68,7 @@ public function __construct( * @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 +85,12 @@ public function getTileSources($manifest_url) { try { // Request the manifest. - $manifest_response = $this->httpClient->get($manifest_url); + //$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(); From e46b10faa51490aeaa77b6191b4f38e5be30f7f4 Mon Sep 17 00:00:00 2001 From: Kyle Huynh <7862086+kylehuynh205@users.noreply.github.com> Date: Thu, 6 Jul 2023 15:53:14 -0400 Subject: [PATCH 2/3] Update openseadragon.module --- openseadragon.module | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/openseadragon.module b/openseadragon.module index 161e42d..6601af1 100644 --- a/openseadragon.module +++ b/openseadragon.module @@ -96,6 +96,11 @@ 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, + + // for dsu-utsc + 'loadTilesWithAjax' => TRUE, + 'ajaxWithCredentials' => TRUE, + 'ajaxHeaders' => ["Authorization" => "Bearer " . \Drupal::service('jwt.authentication.jwt')->generateToken(), 'token' => \Drupal::service('jwt.authentication.jwt')->generateToken() ], ] + $viewer_settings, ]; @@ -114,7 +119,7 @@ function template_preprocess_openseadragon_iiif_manifest_block(&$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'], \Drupal::service('jwt.authentication.jwt')->generateToken()); if (empty($tile_sources)) { $cache_meta->applyTo($variables); @@ -148,6 +153,11 @@ 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, + + // for dsu-utsc + 'loadTilesWithAjax' => TRUE, + 'ajaxWithCredentials' => TRUE, + 'ajaxHeaders' => ["Authorization" => "Bearer " . \Drupal::service('jwt.authentication.jwt')->generateToken(), 'token' => \Drupal::service('jwt.authentication.jwt')->generateToken() ], ] + $viewer_settings, ]; From 9ceb5d42dc0264592a29dbb3849907535764fdd8 Mon Sep 17 00:00:00 2001 From: Kyle Huynh Date: Thu, 6 Jul 2023 16:36:22 -0400 Subject: [PATCH 3/3] Tune the code for phpcs test --- openseadragon.module | 23 +++++++++++++++-------- src/IIIFManifestParser.php | 10 ++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/openseadragon.module b/openseadragon.module index 6601af1..cd6b64d 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'], @@ -97,10 +98,13 @@ function template_preprocess_openseadragon_formatter(&$variables) { 'prefixUrl' => 'https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/images/', 'tileSources' => $tile_sources, - // for dsu-utsc - 'loadTilesWithAjax' => TRUE, - 'ajaxWithCredentials' => TRUE, - 'ajaxHeaders' => ["Authorization" => "Bearer " . \Drupal::service('jwt.authentication.jwt')->generateToken(), 'token' => \Drupal::service('jwt.authentication.jwt')->generateToken() ], + // For dsu-utsc. + 'loadTilesWithAjax' => TRUE, + 'ajaxWithCredentials' => TRUE, + 'ajaxHeaders' => [ + "Authorization" => "Bearer " . $access_token, + 'token' => $access_token, + ], ] + $viewer_settings, ]; @@ -116,10 +120,10 @@ function template_preprocess_openseadragon_formatter(&$variables) { */ function template_preprocess_openseadragon_iiif_manifest_block(&$variables) { $cache_meta = CacheableMetadata::createFromRenderArray($variables); - + $access_token = \Drupal::service('jwt.authentication.jwt')->generateToken(); // Get the tile sources from the manifest. $parser = \Drupal::service('openseadragon.manifest_parser'); - $tile_sources = $parser->getTileSources($variables['iiif_manifest_url'], \Drupal::service('jwt.authentication.jwt')->generateToken()); + $tile_sources = $parser->getTileSources($variables['iiif_manifest_url'], $access_token); if (empty($tile_sources)) { $cache_meta->applyTo($variables); @@ -154,10 +158,13 @@ function template_preprocess_openseadragon_iiif_manifest_block(&$variables) { 'prefixUrl' => 'https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/images/', 'tileSources' => $tile_sources, - // for dsu-utsc + // For dsu-utsc. 'loadTilesWithAjax' => TRUE, 'ajaxWithCredentials' => TRUE, - 'ajaxHeaders' => ["Authorization" => "Bearer " . \Drupal::service('jwt.authentication.jwt')->generateToken(), 'token' => \Drupal::service('jwt.authentication.jwt')->generateToken() ], + 'ajaxHeaders' => [ + "Authorization" => "Bearer " . $access_token, + 'token' => $access_token, + ], ] + $viewer_settings, ]; diff --git a/src/IIIFManifestParser.php b/src/IIIFManifestParser.php index 8bbaca8..d71b13c 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, $access_token=NULL) { + public function getTileSources($manifest_url, $access_token = NULL) { // Try to construct the URL out of a tokenized string // if the node is available. @@ -85,11 +87,11 @@ public function getTileSources($manifest_url, $access_token=NULL) { try { // Request the manifest. - //$manifest_response = $this->httpClient->get($manifest_url); + // $manifest_response = $this->httpClient->get($manifest_url); $manifest_response = $this->httpClient->request('GET', $manifest_url, [ 'headers' => [ - 'Authorization' => 'Bearer ' . $access_token, - ] + 'Authorization' => 'Bearer ' . $access_token, + ], ]); // Decode the manifest json.