Skip to content

Commit be9936b

Browse files
committed
Allow OSD to show on restricted paged objects.
- Alternate implementation of #51 - Resolves yorkulibraries/yudl_drupal_theme#78
1 parent 8cd4b26 commit be9936b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

openseadragon.module

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function template_preprocess_openseadragon_formatter(&$variables) {
8989
$variables['#attached']['library'] = [
9090
'openseadragon/init',
9191
];
92+
$access_token = \Drupal::service('jwt.authentication.jwt')->generateToken();
9293
$variables['#attached']['drupalSettings']['openseadragon'][$openseadragon_viewer_id] = [
9394
'basePath' => Url::fromUri($iiif_address),
9495
'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'],
@@ -110,11 +111,12 @@ function template_preprocess_openseadragon_formatter(&$variables) {
110111
* Implements template_preprocess_HOOK().
111112
*/
112113
function template_preprocess_openseadragon_iiif_manifest_block(&$variables) {
114+
$access_token = \Drupal::service('jwt.authentication.jwt')->generateToken();
113115
$cache_meta = CacheableMetadata::createFromRenderArray($variables);
114116

115117
// Get the tile sources from the manifest.
116118
$parser = \Drupal::service('openseadragon.manifest_parser');
117-
$tile_sources = $parser->getTileSources($variables['iiif_manifest_url']);
119+
$tile_sources = $parser->getTileSources($variables['iiif_manifest_url'], $access_token);
118120

119121
if (empty($tile_sources)) {
120122
$cache_meta->applyTo($variables);

src/IIIFManifestParser.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ public function __construct(
6464
*
6565
* @param string $manifest_url
6666
* The location of the IIIF manifest, which can include tokens.
67+
* @param string $access_token
68+
* The JWT Access token.
6769
*
6870
* @return array
6971
* The URLs of all the tile sources in a manifest.
7072
*/
71-
public function getTileSources($manifest_url) {
73+
public function getTileSources($manifest_url, $access_token = NULL) {
7274

7375
// Try to construct the URL out of a tokenized string
7476
// if the node is available.
@@ -85,7 +87,16 @@ public function getTileSources($manifest_url) {
8587

8688
try {
8789
// Request the manifest.
88-
$manifest_response = $this->httpClient->get($manifest_url);
90+
if (empty($access_token)) {
91+
$manifest_response = $this->httpClient->get($manifest_url);
92+
}
93+
else {
94+
$manifest_response = $this->httpClient->request('GET', $manifest_url, [
95+
'headers' => [
96+
'Authorization' => 'Bearer ' . $access_token,
97+
],
98+
]);
99+
}
89100

90101
// Decode the manifest json.
91102
$manifest_string = (string) $manifest_response->getBody();

0 commit comments

Comments
 (0)