Can pdiiif download images that require authentication?
We're using pdiiif within a Mirador plugin in order to download PDFs of images within the viewer. I am running into issues with pdiiif not passing the authentication cookie for restricted images. When it attempts to download a restricted image it just returns a PDF with all blank pages. The browser console returns a bunch of 401 codes for the images it is attempting to turn into a PDF.
Would you be able to add the ability to pass credentials / cookies using pdiiif?
Let me know what you think. Thanks!
Should be doable, at least for client-side PDF generation. It's not possible (for good reason) for the "no cors" server-side generation fallback, though. I'll try to see if I can get at least cover page generation on the server to work.
OK, so I looked into it, I think it's going to work, but will come with quite a list of requirements for the Image API endpoints:
- Server Auth Coookie for the Image API endpoints must have
SameSite=NoneandSecureset - Server Response for the Image API endpoints must have the
Access-Control-Allow-Credentials:trueheader - Server Response for the Image API endpoints must include the origin domain for the request (i.e. the domain your Mirador instance is hosted on) in the
Access-Control-Allow-Originheader. The header must not be set to*.
Reason for all of that is that pdiiif needs to access the image data in JavaScript to include it in the PDF, which means we have to to deal with CORS for image requests.
Background here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#including_credentials
I pushed a commit with a preliminary implementation to the credentials branch, could you test it for me? I don't have any manifests with authenticated Image API endpoints myself, so i can't really test it right now.
Thank you so much! I will take a look and test this out today.
Did you get a chance to try this @phil-plencner-hl ?
Hi sorry for the delay on testing the credentials branch for pdiiif, I was out of the office most of last week.
I’m trying to install pdiiif as a package using that branch in a mirador plugin and I keep running into problems. The current error I’m seeing is:
Unsupported URL Type "workspace:": workspace:^
I’m not sure how else I can test these changes within a plugin?
This is the plugin: https://github.com/harvard-lts/mirador-pdiiif-plugin/
This is the command I was attempting to run (I realized just trying to install the branch directly at the root of the repo doesn’t seem to work because there is no package.json file there….)
npm install "https://gitpkg.now.sh/jbaiter/pdiiif/pdiiif-api?credentials"
I also tried installing pnpm and running a similar command and got the following error:
ERR_PNPM_WORKSPACE_PKG_NOT_FOUND In : "pdiiif@workspace:^" is in the dependencies but no package named "pdiiif" is present in the workspace
I'm wondering if I just have to build it locally on the branch and include the built code in the plugin somehow?
Let me know if you have any ideas…
Sorry about that! The project is setup as a pnpm workspace. If you're only using the library (pdiiif-lib) and not the web interface (pdiiif-web) or the fallback server (pdiiif-api), it should be enough to run npm i ~/path/to/pdiiif-repo/pdiiif-lib. The directory contains a standalone package.json without references to other workspace components.
I couldn't get that to work either, unfortunately. Because we are deploying the plugin to our development environments using Github Actions, it doesn't have access to the local files and fails when trying to build.
I attempted to make a patch to pdiiif in our Mirador plugin using the patch-package module, but I'm running into problems there too. It seems like the credentials branch is off of tag 0.2.7 in Github but the latest tag in npmjs is 0.2.5, so the patching fails.
Would you be able to publish the 0.2.7 tag to npmjs or is that still under development?
Actually, I think I was just able to get it patched and deployed in our plugin. I should be able to test it today / tomorrow. I'll let you know how it goes!
Hey @phil-plencner-hl, did you get a chance to test this? I'm preparing a new release and would love to get this in, if it solved your problem :-)