feat(route): add back twitter 2fa (#15292)

ref: 95ace09917
This commit is contained in:
Tony 2024-04-19 22:29:34 +08:00 committed by GitHub
parent 1a3720ab4d
commit b3eb3f3a0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 28 deletions

View File

@ -261,6 +261,7 @@ export type Config = {
oauthTokenSecrets?: string[];
username?: string;
password?: string;
authenticationSecret?: string;
cookie?: string;
};
weibo: {
@ -613,6 +614,7 @@ const calculateValue = () => {
oauthTokenSecrets: envs.TWITTER_OAUTH_TOKEN_SECRET?.split(','),
username: envs.TWITTER_USERNAME,
password: envs.TWITTER_PASSWORD,
authenticationSecret: envs.TWITTER_AUTHENTICATION_SECRET,
cookie: envs.TWITTER_COOKIE,
},
weibo: {

View File

@ -6,12 +6,14 @@ import ofetch from '@/utils/ofetch';
import crypto from 'crypto';
import { config } from '@/config';
import { v5 as uuidv5 } from 'uuid';
import { authenticator } from 'otplib';
import logger from '@/utils/logger';
import cache from '@/utils/cache';
const NAMESPACE = 'd41d092b-b007-48f7-9129-e9538d2d8fe9';
const username = config.twitter.username;
const password = config.twitter.password;
const authenticationSecret = config.twitter.authenticationSecret;
let authentication = null;
@ -133,38 +135,37 @@ async function login() {
});
logger.debug('Twitter login 5 finished: AccountDuplicationCheck.');
for (const subtask of task4.data?.subtasks || []) {
for await (const subtask of task4.data?.subtasks || []) {
if (subtask.open_account) {
authentication = subtask.open_account;
break;
} else if (subtask.subtask_id === 'LoginTwoFactorAuthChallenge') {
// const token = authenticator.generate(authenticationSecret);
const token = authenticator.generate(authenticationSecret);
// // eslint-disable-next-line no-await-in-loop
// const task5 = await got.post('https://api.twitter.com/1.1/onboarding/task.json', {
// headers,
// json: {
// flow_token: task4.data.flow_token,
// subtask_inputs: [
// {
// enter_text: {
// suggestion_id: null,
// text: token,
// link: 'next_link',
// },
// subtask_id: 'LoginTwoFactorAuthChallenge',
// },
// ],
// },
// });
// logger.debug('Twitter login 6 finished: LoginTwoFactorAuthChallenge.');
const task5 = await got.post('https://api.twitter.com/1.1/onboarding/task.json', {
headers,
json: {
flow_token: task4.data.flow_token,
subtask_inputs: [
{
enter_text: {
suggestion_id: null,
text: token,
link: 'next_link',
},
subtask_id: 'LoginTwoFactorAuthChallenge',
},
],
},
});
logger.debug('Twitter login 6 finished: LoginTwoFactorAuthChallenge.');
// for (const subtask of task5.data?.subtasks || []) {
// if (subtask.open_account) {
// authentication = subtask.open_account;
// break;
// }
// }
for (const subtask of task5.data?.subtasks || []) {
if (subtask.open_account) {
authentication = subtask.open_account;
break;
}
}
break;
}
}

View File

@ -40,8 +40,8 @@ generates
Currently supports two authentication methods:
- Using TWITTER_COOKIE (recommended): Configure the cookies of logged-in Twitter Web, at least including the fields auth_token and ct0. RSSHub will use this information to directly access Twitter's web API to obtain data.
- Using \`TWITTER_COOKIE\` (recommended): Configure the cookies of logged-in Twitter Web, at least including the fields auth_token and ct0. RSSHub will use this information to directly access Twitter's web API to obtain data.
- Using TWITTER_USERNAME TWITTER_PASSWORD: Configure the Twitter username and password. RSSHub will use this information to log in to Twitter and obtain data using the mobile API. Please note that if you have not logged in with the current IP address before, it is easy to trigger Twitter's risk control mechanism.
- Using \`TWITTER_USERNAME\` \`TWITTER_PASSWORD\` and \`TWITTER_AUTHENTICATION_SECRET\`: Configure the Twitter username and password. RSSHub will use this information to log in to Twitter and obtain data using the mobile API. Please note that if you have not logged in with the current IP address before, it is easy to trigger Twitter's risk control mechanism.
`,
};

View File

@ -21,6 +21,11 @@ export const route: Route = {
name: 'TWITTER_PASSWORD',
description: 'Please see above for details.',
},
{
name: 'TWITTER_AUTHENTICATION_SECRET',
description: 'TOTP 2FA secret, please see above for details.',
optional: true,
},
{
name: 'TWITTER_COOKIE',
description: 'Please see above for details.',