Security
Manage your account security: passwords, two-factor authentication, sessions, backup codes, and connected applications.
account.verifyPassword(password)
Verify a password against the current account. Useful for confirming the user's identity before sensitive operations. Uses the v1.1 account/verify_password endpoint.
const result = await client.account.verifyPassword("my_password");
console.log(result.status); // "ok"account.changePassword(currentPassword, newPassword)
Change your account password. Uses the v1.1 account/change_password endpoint.
Warning
Requires elevated access. Call client.elevate(password) first.
await client.elevate("current_password");
await client.account.changePassword("current_password", "new_secure_password");account.passwordStrength(password)
Check the strength of a password before setting it. Uses the v1.1 account/password_strength endpoint.
const strength = await client.account.passwordStrength("my_new_password_123");
console.log(strength);Tip
Always check password strength before calling changePassword() to ensure the new password meets Twitter's requirements.
Two-Factor Authentication
account.twoFactor()
Get your enabled two-factor methods. Uses the GraphQL login_verificationQuery.
account.twoFactorPhone()
Get whether two-factor is on and which methods are enabled. Uses the GraphQL phoneQuery.
account.twoFactorMethods(userId?)
Get every two-factor method, including security keys, from the twoFactorAuthSettings2 strato column.
account.beginSms2FA()
Start SMS two-factor enrollment. Returns the masked phone number and a session_token. Uses the GraphQL login_verification_enrollmentBeginSmsMutation.
account.finishSms2FA(sessionToken)
Finish SMS two-factor enrollment. Returns backup codes.
const { session_token } = await client.account.beginSms2FA();
const { backup_codes } = await client.account.finishSms2FA(session_token);account.disable2FA()
Disable two-factor authentication on your account. Uses the v1.1 account/login_verification_enrollment endpoint.
Deprecated
The web client no longer calls account/login_verification_enrollment.
Warning
Requires elevated access. Call client.elevate(password) first.
await client.elevate("your_password");
await client.account.disable2FA();account.remove2FAMethod(methodId)
Remove a specific 2FA method, such as a security key or authenticator app. Uses the v1.1 account/login_verification/remove_method endpoint.
Deprecated
The web client no longer calls account/login_verification/remove_method.
await client.account.remove2FAMethod("method_id_here");account.tempPassword()
Generate a temporary password for app-specific login. This is useful when your account has 2FA enabled and you need to authenticate in a context that doesn't support interactive 2FA. Uses the v1.1 account/login_verification/temporary_password endpoint.
Deprecated
The web client no longer calls account/login_verification/temporary_password.
const temp = await client.account.tempPassword();
console.log(temp);account.renameSecurityKey(methodId, name)
Rename a registered security key (e.g. a YubiKey or passkey). Uses the v1.1 account/login_verification/rename_security_key_method endpoint.
Deprecated
The web client no longer calls account/login_verification/rename_security_key_method.
await client.account.renameSecurityKey("method_id", "My YubiKey 5");Backup Codes
account.backupCode()
Get your current backup code. Backup codes can be used to regain access to your account if you lose your 2FA device. Uses the v1.1 account/backup_code endpoint (GET).
const code = await client.account.backupCode();
console.log(`Your backup code: ${code}`);account.generateBackupCode()
Generate a new backup code, invalidating the previous one. Uses the v1.1 account/backup_code endpoint (POST).
const newCode = await client.account.generateBackupCode();
console.log(`New backup code: ${newCode}`);Danger
Generating a new backup code will invalidate your previous code. Make sure to store the new code in a safe place.
Sessions
account.sessions()
List the login sessions on your account. Each has a hashed token, name, icon_type, last_seen_time_ms and is_current_session. Uses the GraphQL UserSessionsList query.
const sessions = await client.account.sessions();account.sessionDetail()
Same list through the Relay sessionDetailQuery, which also carries location.
account.revokeSession(token)
Log out one session by its hashed token. Returns the HTTP status.
const [, other] = await client.account.sessions();
await client.account.revokeSession(other.token);account.revokeAllSessions()
Log out every session except the current one. Returns the HTTP status.
Connected Apps
account.connectedApps()
List all third-party applications that have been granted access to your account. Uses the v1.1 oauth/list endpoint.
const apps = await client.account.connectedApps();
console.log(`${apps.length} connected apps`);account.revokeApp(token, opts?)
Revoke access for a connected app. OAuth 1 apps go through v1.1 oauth/revoke. Pass { type: "oauth2" } for OAuth 2 apps, which go through v2 oauth2/revoke_token_hash.
await client.account.revokeApp("app_token_here");
await client.account.revokeApp("token_hash", { type: "oauth2" });account.oauth2Authorize(params)
Get the OAuth 2 consent screen data for an authorize request. params are the query parameters of the authorize URL: client_id, code_challenge, code_challenge_method, redirect_uri, response_type, scope and state.
account.oauth2Approve(params, opts?)
Approve or deny an OAuth 2 authorize request. Returns the redirect_uri.
const { redirect_uri } = await client.account.oauth2Approve(params, { approval: true });Single Sign-On
account.deleteSSOConnection(connectionId)
Delete an SSO (Single Sign-On) connection linked to your account (e.g. Google or Apple sign-in). Uses the v1.1 sso/delete_connection endpoint.
Deprecated
The web client no longer calls sso/delete_connection.
await client.account.deleteSSOConnection("connection_id");account.emailYourData()
Request an email containing a copy of your Twitter data (tweets, DMs, profile info, etc.). Uses the v1.1 account/personalization/email_your_data endpoint.
await client.account.emailYourData();Full example
// Verify current password
const result = await client.account.verifyPassword("my_password");
console.log(`Password valid: ${result.status}`);
// Check strength of a new password
const strength = await client.account.passwordStrength("new_p@ssw0rd_2025!");
// Elevate session for sensitive operations
await client.elevate("my_password");
// Change password
await client.account.changePassword("my_password", "new_p@ssw0rd_2025!");
// View active sessions
const sessions = await client.account.sessions();
console.log(`Active sessions: ${JSON.stringify(sessions)}`);
// Manage backup codes
const currentCode = await client.account.backupCode();
console.log(`Current backup code: ${currentCode}`);
const newCode = await client.account.generateBackupCode();
console.log(`New backup code: ${newCode}`);
// Review and revoke connected apps
const apps = await client.account.connectedApps();
for (const app of apps) {
console.log(`Connected app: ${JSON.stringify(app)}`);
}
// Revoke a specific app
await client.account.revokeApp("app_token_here");
// Manage 2FA
await client.elevate("your_password");
await client.account.disable2FA();
// Rename a security key
await client.account.renameSecurityKey("method_id", "Office YubiKey");
// Remove a specific 2FA method
await client.account.remove2FAMethod("method_id");
// Generate a temporary password for app login
const temp = await client.account.tempPassword();
// Remove an SSO connection
await client.account.deleteSSOConnection("connection_id");
// Request a copy of your data
await client.account.emailYourData();