-
Notifications
You must be signed in to change notification settings - Fork 165
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
fix(download): import to bookshelf from a link with an opdf authwall from the downloader service (opds, cli, ...) #2733
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tested with https://github.com/panaC/opds2-auth-test-server on localhost:8282 with this patch :
And with this basic authentication http file server on localhost:3000 : const http = require('http');
const fs = require('fs');
const path = require('path');
const publicationPath = path.join(__dirname, 'childrens-literature.epub'); // Path to your publication file
const authUsername = 'admin';
const authPassword = 'admin';
const server = http.createServer((req, res) => {
// Check for Authorization header
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Basic ')) {
// Return 401 with OPDS authentication JSON
res.statusCode = 401;
res.setHeader('Content-Type', 'application/opds-authentication+json');
res.end(JSON.stringify({
"title": "basic auth",
"id": "",
"links": [
{
"type": "image/jpeg",
"rel": "logo",
"href": "https://www.edrlab.org/wp-content/uploads/2016/12/[email protected]"
}
],
"authentication": [
{
"type": "http://opds-spec.org/auth/basic",
"labels": {
"login": "LOGIN",
"password": "PASSWORD"
}
}
],
"err": null,
"info": "Basic realm=\"login\""
}));
console.log("not authHeader", authHeader);
return;
}
// Extract credentials from Authorization header
const credentials = Buffer.from(authHeader.substring(6), 'base64').toString('utf8').split(':');
const username = credentials[0];
const password = credentials[1];
// Verify credentials
if (username !== authUsername || password !== authPassword) {
// Return 401 with OPDS authentication JSON
res.statusCode = 401;
res.setHeader('Content-Type', 'application/opds-authentication+json');
res.end(JSON.stringify({
"title": "basic auth",
"id": "",
"links": [
{
"type": "image/jpeg",
"rel": "logo",
"href": "https://www.edrlab.org/wp-content/uploads/2016/12/[email protected]"
}
],
"authentication": [
{
"type": "http://opds-spec.org/auth/basic",
"labels": {
"login": "LOGIN",
"password": "PASSWORD"
}
}
],
"err": null,
"info": "Basic realm=\"login\""
}));
console.log("not admin:admin", username, password);
return;
}
// Serve the publication file if authenticated
res.setHeader('Content-Type', 'application/epub+zip');
fs.createReadStream(publicationPath).pipe(res);
});
server.listen(3000, () => {
console.log('Server running on port 3000');
}); |
This works great with a private OPDS feed located behind a VPN (cannot share here), merging this PR now. |
I filed a separate issue for the LCP JSON ZIP injection regression bug: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #2512 (comment)
close and replace #2732