Spaces:
Running
Running
debug: add /app/test-request-token to call generateAuthLink directly
Browse files- health-server.js +45 -0
health-server.js
CHANGED
|
@@ -1868,6 +1868,51 @@ const server = http.createServer((req, res) => {
|
|
| 1868 |
return;
|
| 1869 |
}
|
| 1870 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1871 |
// ββ /app/read-x-provider β Show x.provider.ts source from container βββββ
|
| 1872 |
if (pathname === "/app/read-x-provider") {
|
| 1873 |
try {
|
|
|
|
| 1868 |
return;
|
| 1869 |
}
|
| 1870 |
|
| 1871 |
+
// ββ /app/test-request-token β Test generateAuthLink via CF proxy βββββββββ
|
| 1872 |
+
if (pathname === "/app/test-request-token" || pathname === "/app/test-request-token/") {
|
| 1873 |
+
(async () => {
|
| 1874 |
+
const lines = ["=== TEST: generateAuthLink via CF proxy ===", ""];
|
| 1875 |
+
try {
|
| 1876 |
+
const apiKey = process.env.X_API_KEY || "";
|
| 1877 |
+
const apiSecret = process.env.X_API_SECRET || "";
|
| 1878 |
+
lines.push(`X_API_KEY : ${apiKey.slice(0,6)}... (len=${apiKey.length})`);
|
| 1879 |
+
lines.push(`X_API_SECRET : ${apiSecret.slice(0,6)}... (len=${apiSecret.length})`);
|
| 1880 |
+
lines.push(`CLOUDFLARE_PROXY_URL : ${process.env.CLOUDFLARE_PROXY_URL || "(not set)"}`);
|
| 1881 |
+
lines.push(`NODE_OPTIONS : ${process.env.NODE_OPTIONS || "(not set)"}`);
|
| 1882 |
+
lines.push("");
|
| 1883 |
+
|
| 1884 |
+
// Require twitter-api-v2 from Postiz's node_modules
|
| 1885 |
+
const { TwitterApi } = require("/app/node_modules/twitter-api-v2");
|
| 1886 |
+
const callbackUrl = (process.env.FRONTEND_URL || "https://somratpro-huggingpost.hf.space") + "/integrations/social/x";
|
| 1887 |
+
lines.push(`callbackUrl : ${callbackUrl}`);
|
| 1888 |
+
lines.push("Calling generateAuthLink...");
|
| 1889 |
+
|
| 1890 |
+
const client = new TwitterApi({ appKey: apiKey, appSecret: apiSecret });
|
| 1891 |
+
const result = await client.generateAuthLink(callbackUrl, { authAccessType: "write", linkMode: "authenticate", forceLogin: false });
|
| 1892 |
+
|
| 1893 |
+
lines.push("");
|
| 1894 |
+
lines.push(`oauth_token : ${result.oauth_token ? result.oauth_token.slice(0,20) + "... (len=" + result.oauth_token.length + ")" : "(EMPTY!)"}`);
|
| 1895 |
+
lines.push(`oauth_token_secret : ${result.oauth_token_secret ? result.oauth_token_secret.slice(0,10) + "... (len=" + result.oauth_token_secret.length + ")" : "(EMPTY!)"}`);
|
| 1896 |
+
lines.push(`url : ${result.url ? result.url.slice(0,80) : "(EMPTY!)"}`);
|
| 1897 |
+
lines.push("");
|
| 1898 |
+
lines.push("codeVerifier = oauth_token + ':' + oauth_token_secret:");
|
| 1899 |
+
const cv = result.oauth_token + ":" + result.oauth_token_secret;
|
| 1900 |
+
lines.push(` "${cv.slice(0,40)}..." (len=${cv.length})`);
|
| 1901 |
+
if (!result.oauth_token_secret) {
|
| 1902 |
+
lines.push(" β EMPTY SECRET β CF proxy or X returning malformed request_token response!");
|
| 1903 |
+
} else {
|
| 1904 |
+
lines.push(" β secret present");
|
| 1905 |
+
}
|
| 1906 |
+
} catch (e) {
|
| 1907 |
+
lines.push(`ERROR: ${e.message}`);
|
| 1908 |
+
lines.push(e.stack || "");
|
| 1909 |
+
}
|
| 1910 |
+
res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
|
| 1911 |
+
res.end(lines.join("\n"));
|
| 1912 |
+
})();
|
| 1913 |
+
return;
|
| 1914 |
+
}
|
| 1915 |
+
|
| 1916 |
// ββ /app/read-x-provider β Show x.provider.ts source from container βββββ
|
| 1917 |
if (pathname === "/app/read-x-provider") {
|
| 1918 |
try {
|