Skip to content
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

Added TOTP support #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, Streame

twitch_miner = TwitchChannelPointsMiner(
username="your-twitch-username",
otp_secret="",
password="write-your-secure-psw", # If no password will be provided, the script will ask interactively
claim_drops_startup=False, # If you want to auto claim all drops from Twitch inventory on the startup
priority=[ # Custom priority in this case for example:
Expand Down
4 changes: 3 additions & 1 deletion TwitchChannelPointsMiner/TwitchChannelPointsMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
class TwitchChannelPointsMiner:
__slots__ = [
"username",
"otp_secret",
"twitch",
"claim_drops_startup",
"enable_analytics",
Expand All @@ -71,6 +72,7 @@ class TwitchChannelPointsMiner:
def __init__(
self,
username: str,
otp_secret: str,
password: str = None,
claim_drops_startup: bool = False,
enable_analytics: bool = False,
Expand Down Expand Up @@ -105,7 +107,7 @@ def __init__(
Settings.streamer_settings = streamer_settings

user_agent = get_user_agent("FIREFOX")
self.twitch = Twitch(self.username, user_agent, password)
self.twitch = Twitch(self.username, user_agent, otp_secret,password)

self.claim_drops_startup = claim_drops_startup
self.priority = priority if isinstance(priority, list) else [priority]
Expand Down
4 changes: 2 additions & 2 deletions TwitchChannelPointsMiner/classes/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Twitch(object):
"twilight_build_id_pattern",
]

def __init__(self, username, user_agent, password=None):
def __init__(self, username, user_agent, otp_secret,password=None):
cookies_path = os.path.join(Path().absolute(), "cookies")
Path(cookies_path).mkdir(parents=True, exist_ok=True)
self.cookies_file = os.path.join(cookies_path, f"{username}.pkl")
Expand All @@ -71,7 +71,7 @@ def __init__(self, username, user_agent, password=None):
choice(string.ascii_letters + string.digits) for _ in range(32)
)
self.twitch_login = TwitchLogin(
CLIENT_ID, self.device_id, username, self.user_agent, password=password
CLIENT_ID, self.device_id, username, self.user_agent, otp_secret,password=password
)
self.running = True
self.integrity = None
Expand Down
14 changes: 11 additions & 3 deletions TwitchChannelPointsMiner/classes/TwitchLogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import pickle
import pyotp

import requests

Expand Down Expand Up @@ -41,12 +42,13 @@ class TwitchLogin(object):
"session",
"username",
"password",
"otp_secret",
"user_id",
"email",
"cookies"
]

def __init__(self, client_id, device_id, username, user_agent, password=None):
def __init__(self, client_id, device_id, username, user_agent, otp_secret,password=None):
self.client_id = client_id
self.device_id = device_id
self.token = None
Expand All @@ -57,6 +59,7 @@ def __init__(self, client_id, device_id, username, user_agent, password=None):
)
self.username = username
self.password = password
self.otp_secret = otp_secret
self.user_id = None
self.email = None

Expand Down Expand Up @@ -95,11 +98,16 @@ def login_flow(self):
err_code = login_response["error_code"]
if err_code in [3011, 3012]: # missing 2fa token
if err_code == 3011:
logger.info(
if self.otp_secret == "":
logger.info(
"Two factor authentication enabled, please enter token below."
)
)
else:
post_data["authy_token"] = pyotp.TOTP(self.otp_secret).now() #HIER MAX
continue
else:
logger.info("Invalid two factor token, please try again.")


twofa = input("2FA token: ")
post_data["authy_token"] = twofa.strip()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ colorama
flask
irc
pandas
pyotp