File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ function template_preprocess_openseadragon_formatter(&$variables) {
89
89
$variables['#attached']['library'] = [
90
90
'openseadragon/init',
91
91
];
92
+ $access_token = \Drupal::service('jwt.authentication.jwt')->generateToken();
92
93
$variables['#attached']['drupalSettings']['openseadragon'][$openseadragon_viewer_id] = [
93
94
'basePath' => Url::fromUri($iiif_address),
94
95
'fitToAspectRatio' => $viewer_settings['fit_to_aspect_ratio'],
@@ -110,11 +111,12 @@ function template_preprocess_openseadragon_formatter(&$variables) {
110
111
* Implements template_preprocess_HOOK().
111
112
*/
112
113
function template_preprocess_openseadragon_iiif_manifest_block(&$variables) {
114
+ $access_token = \Drupal::service('jwt.authentication.jwt')->generateToken();
113
115
$cache_meta = CacheableMetadata::createFromRenderArray($variables);
114
116
115
117
// Get the tile sources from the manifest.
116
118
$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 );
118
120
119
121
if (empty($tile_sources)) {
120
122
$cache_meta->applyTo($variables);
Original file line number Diff line number Diff line change @@ -64,11 +64,13 @@ public function __construct(
64
64
*
65
65
* @param string $manifest_url
66
66
* The location of the IIIF manifest, which can include tokens.
67
+ * @param string $access_token
68
+ * The JWT Access token.
67
69
*
68
70
* @return array
69
71
* The URLs of all the tile sources in a manifest.
70
72
*/
71
- public function getTileSources ($ manifest_url ) {
73
+ public function getTileSources ($ manifest_url, $ access_token = NULL ) {
72
74
73
75
// Try to construct the URL out of a tokenized string
74
76
// if the node is available.
@@ -85,7 +87,16 @@ public function getTileSources($manifest_url) {
85
87
86
88
try {
87
89
// 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
+ }
89
100
90
101
// Decode the manifest json.
91
102
$ manifest_string = (string ) $ manifest_response ->getBody ();
You can’t perform that action at this time.
0 commit comments