Browse Source

Islandora IIIF: Add auth headers to IIIF Info request.

959-hocr-tiff-performance
Alexander O'Neill 11 months ago
parent
commit
4450248078
  1. 2
      modules/islandora_iiif/islandora_iiif.services.yml
  2. 20
      modules/islandora_iiif/src/IiifInfo.php

2
modules/islandora_iiif/islandora_iiif.services.yml

@ -1,4 +1,4 @@
services:
islandora_iiif:
class: Drupal\islandora_iiif\IiifInfo
arguments: ['@config.factory', '@http_client', '@logger.channel.islandora']
arguments: ['@config.factory', '@http_client', '@logger.channel.islandora', '@jwt.authentication.jwt']

20
modules/islandora_iiif/src/IiifInfo.php

@ -5,6 +5,8 @@ namespace Drupal\islandora_iiif;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\file\FileInterface;
use Drupal\jwt\Authentication\Provider\JwtAuth;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
@ -36,6 +38,13 @@ class IiifInfo {
*/
protected $iiifConfig;
/**
* JWT Auth provider service.
*
* @var \Drupal\jwt\Authentication\Provider\JwtAuth
*/
protected $jwtAuth;
/**
* The logger.
*
@ -53,13 +62,16 @@ class IiifInfo {
* The HTTP Client.
* @param \Drupal\Core\Logger\LoggerChannelInterface $channel
* Logger channel.
* @param \Drupal\jwt\Authentication\Provider\JwtAuth $jwt_auth
* The JWT auth provider.
*/
public function __construct(ConfigFactoryInterface $config_factory, Client $http_client, LoggerChannelInterface $channel) {
public function __construct(ConfigFactoryInterface $config_factory, Client $http_client, LoggerChannelInterface $channel, JwtAuth $jwt_auth) {
$this->configFactory = $config_factory;
$this->iiifConfig= $this->configFactory->get('islandora_iiif.settings');
$this->httpClient = $http_client;
$this->logger = $channel;
$this->jwtAuth = $jwt_auth;
}
/**
@ -95,7 +107,11 @@ class IiifInfo {
public function getImageDimensions(FileInterface $file) {
$iiif_url = $this->baseUrl($file);
try {
$info_json = $this->httpClient->get($iiif_url)->getBody();
$info_json = $this->httpClient->request('get', $iiif_url, [
'headers' => [
'Authorization' => 'bearer ' . $this->jwtAuth->generateToken()
]
])->getBody();
$resource = json_decode($info_json, TRUE);
$width = $resource['width'];
$height = $resource['height'];

Loading…
Cancel
Save