-
Notifications
You must be signed in to change notification settings - Fork 15
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
View restricted access content #51
base: 2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,13 +89,22 @@ 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'], | ||
'options' => [ | ||
'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 " . $access_token, | ||
'token' => $access_token, | ||
], | ||
Comment on lines
+102
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much the same as the previous PR, these tokens are generally expected to be valid for a limited length of time, so we would have to propagate cache headers preventing them from being used beyond their lifetime to prevent serving up responses with invalid tokens.
Comment on lines
+100
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is feedback from a Slack conversation. Testing this on our instance, if we leave this two blocks in (kylehuynh205@9ceb5d4#diff-6d693de3726ed28241d0e4b5045e66eff4e2e82da162a08975768d342ec2ed7eR161-R167 and kylehuynh205@9ceb5d4#diff-6d693de3726ed28241d0e4b5045e66eff4e2e82da162a08975768d342ec2ed7eR101-R107), images are not displayed in the viewer, and we get CORS errors. If I remove the two blocks, everything works fine, including the original issue I had with the viewer not working on paged objects that used OSD. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a good compromise here would be to add these values
...then if the above is set to |
||
] + $viewer_settings, | ||
]; | ||
|
||
|
@@ -111,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']); | ||
$tile_sources = $parser->getTileSources($variables['iiif_manifest_url'], $access_token); | ||
|
||
if (empty($tile_sources)) { | ||
$cache_meta->applyTo($variables); | ||
|
@@ -148,6 +157,14 @@ 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer quite true if this is to be pushed into the base code. |
||
'loadTilesWithAjax' => TRUE, | ||
'ajaxWithCredentials' => TRUE, | ||
'ajaxHeaders' => [ | ||
"Authorization" => "Bearer " . $access_token, | ||
'token' => $access_token, | ||
], | ||
Comment on lines
+162
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much the same as the previous PR, these tokens are generally expected to be valid for a limited length of time, so we would have to propagate cache headers preventing them from being used beyond their lifetime to prevent serving up responses with invalid tokens. |
||
] + $viewer_settings, | ||
]; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,12 @@ public function getTileSources($manifest_url) { | |
|
||
try { | ||
// Request the manifest. | ||
$manifest_response = $this->httpClient->get($manifest_url); | ||
// $manifest_response = $this->httpClient->get($manifest_url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented out code shouldn't be here. |
||
$manifest_response = $this->httpClient->request('GET', $manifest_url, [ | ||
'headers' => [ | ||
'Authorization' => 'Bearer ' . $access_token, | ||
], | ||
]); | ||
Comment on lines
+91
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure that this makes sense in the case Really, if we want to be sure to always have a token here, why not just generate it here? |
||
|
||
// Decode the manifest json. | ||
$manifest_string = (string) $manifest_response->getBody(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer quite true if this is to be pushed into the base code.