Fix Jackett widget when using password (#3097)
Fixes the error that occurs as seen in (#437, #1799 and #2794) which occurs due to the way password authentication works in Jackett. We now make a login request to Jackett to get the cookie and then use that cookie to make the actual request to the Jackett API.
This commit is contained in:
parent
7e0fbed06b
commit
b97d625c93
@ -5,7 +5,7 @@ description: Jackett Widget Configuration
|
|||||||
|
|
||||||
Learn more about [Jackett](https://github.com/Jackett/Jackett).
|
Learn more about [Jackett](https://github.com/Jackett/Jackett).
|
||||||
|
|
||||||
Jackett must not have any authentication for the widget to work.
|
If Jackett has an admin password set, you must set the `password` field for the widget to work.
|
||||||
|
|
||||||
Allowed fields: `["configured", "errored"]`.
|
Allowed fields: `["configured", "errored"]`.
|
||||||
|
|
||||||
@ -14,4 +14,5 @@ widget:
|
|||||||
type: jackett
|
type: jackett
|
||||||
url: http://jackett.host.or.ip
|
url: http://jackett.host.or.ip
|
||||||
key: jackettapikey
|
key: jackettapikey
|
||||||
|
password: JackettAdminPassword
|
||||||
```
|
```
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import validateWidgetData from "utils/proxy/validate-widget-data";
|
|||||||
import { httpProxy } from "utils/proxy/http";
|
import { httpProxy } from "utils/proxy/http";
|
||||||
import createLogger from "utils/logger";
|
import createLogger from "utils/logger";
|
||||||
import widgets from "widgets/widgets";
|
import widgets from "widgets/widgets";
|
||||||
|
import { fetchJackettCookie } from "utils/proxy/jackett";
|
||||||
|
|
||||||
const logger = createLogger("credentialedProxyHandler");
|
const logger = createLogger("credentialedProxyHandler");
|
||||||
|
|
||||||
@ -69,6 +70,15 @@ export default async function credentialedProxyHandler(req, res, map) {
|
|||||||
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
|
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
|
||||||
} else if (widget.type === "plantit") {
|
} else if (widget.type === "plantit") {
|
||||||
headers.Key = `${widget.key}`;
|
headers.Key = `${widget.key}`;
|
||||||
|
} else if (widget.type === "jackett") {
|
||||||
|
if (widget.password) {
|
||||||
|
const jackettCookie = await fetchJackettCookie(widget, widgets[widget.type].loginURL);
|
||||||
|
if (jackettCookie) {
|
||||||
|
headers.Cookie = jackettCookie;
|
||||||
|
} else {
|
||||||
|
return res.status(500).json({ error: "Failed to authenticate with Jackett" });
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
headers["X-API-Key"] = `${widget.key}`;
|
headers["X-API-Key"] = `${widget.key}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,7 +103,7 @@ export async function httpProxy(url, params = {}) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const [status, contentType, data, responseHeaders] = await request;
|
const [status, contentType, data, responseHeaders] = await request;
|
||||||
return [status, contentType, data, responseHeaders];
|
return [status, contentType, data, responseHeaders, params];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(
|
logger.error(
|
||||||
"Error calling %s//%s%s%s...",
|
"Error calling %s//%s%s%s...",
|
||||||
|
|||||||
22
src/utils/proxy/jackett.js
Normal file
22
src/utils/proxy/jackett.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { httpProxy } from "utils/proxy/http";
|
||||||
|
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||||
|
|
||||||
|
export async function fetchJackettCookie(widget, loginURL) {
|
||||||
|
const url = new URL(formatApiCall(loginURL, widget));
|
||||||
|
const loginData = `password=${encodeURIComponent(widget.password)}`;
|
||||||
|
const [status, , , , params] = await httpProxy(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
},
|
||||||
|
body: loginData,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (status === 200 && params && params.headers && params.headers.Cookie) {
|
||||||
|
const cookieValue = params.headers.Cookie;
|
||||||
|
return cookieValue;
|
||||||
|
} else {
|
||||||
|
logger.error("Failed to fetch Jackett cookie, status: %d", status);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,9 @@
|
|||||||
import genericProxyHandler from "utils/proxy/handlers/generic";
|
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||||
|
|
||||||
const widget = {
|
const widget = {
|
||||||
api: "{url}/api/v2.0/{endpoint}?apikey={key}&configured=true",
|
api: "{url}/api/v2.0/{endpoint}?apikey={key}&configured=true",
|
||||||
proxyHandler: genericProxyHandler,
|
proxyHandler: credentialedProxyHandler,
|
||||||
|
loginURL: "{url}/UI/Dashboard",
|
||||||
|
|
||||||
mappings: {
|
mappings: {
|
||||||
indexers: {
|
indexers: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user