Ejemplo n.º 1
0
def create_user(app, access_token):
    # Username is not yet known at this point, so fetch it from Mastodon
    user = User(app.instance, None, access_token)
    creds = api.verify_credentials(app, user)

    user = User(app.instance, creds['username'], access_token)
    config.save_user(user, activate=True)

    print_out("Access token saved to config at: <green>{}</green>".format(
        config.get_config_file_path()))

    return user
Ejemplo n.º 2
0
def login_interactive(app):
    print("\nLog in to " + green(app.base_url))
    email = input('Email: ')
    password = getpass('Password: ')

    print("Authenticating...")
    try:
        user = api.login(app, email, password)
    except:
        raise ConsoleError("Login failed")

    save_user(user)
    print("User token saved to " + green(CONFIG_USER_FILE))

    return user
Ejemplo n.º 3
0
def create_user(app, email, access_token):
    user = User(app.instance, email, access_token)
    path = config.save_user(user)

    print_out("Access token saved to: <green>{}</green>".format(path))

    return user
Ejemplo n.º 4
0
def two_factor_login_interactive(app):
    """Hacky implementation of two factor authentication"""

    print_out("Log in to {}".format(app.instance))
    email = input('Email: ')
    password = getpass('Password: '******'/auth/sign_in'

    session = requests.Session()

    # Fetch sign in form
    response = session.get(sign_in_url)
    response.raise_for_status()

    soup = BeautifulSoup(response.content, "html.parser")
    form = soup.find('form')
    inputs = form.find_all('input')

    data = {i.attrs.get('name'): i.attrs.get('value') for i in inputs}
    data['user[email]'] = email
    data['user[password]'] = password

    # Submit form, get 2FA entry form
    response = session.post(sign_in_url, data)
    response.raise_for_status()

    soup = BeautifulSoup(response.content, "html.parser")
    form = soup.find('form')
    inputs = form.find_all('input')

    data = {i.attrs.get('name'): i.attrs.get('value') for i in inputs}
    data['user[otp_attempt]'] = input("2FA Token: ")

    # Submit token
    response = session.post(sign_in_url, data)
    response.raise_for_status()

    # Extract access token from response
    soup = BeautifulSoup(response.content, "html.parser")
    initial_state = soup.find('script', id='initial-state')

    if not initial_state:
        raise ConsoleError("Login failed: Invalid 2FA token?")

    data = json.loads(initial_state.get_text())
    access_token = data['meta']['access_token']

    user = User(app.instance, email, access_token)
    path = config.save_user(user)
    print_out("Access token saved to: <green>{}</green>".format(path))
Ejemplo n.º 5
0
def login_interactive(app):
    print("\nLog in to " + green(app.instance))
    email = input('Email: ')
    password = getpass('Password: '******'access_token'])
    path = config.save_user(user)
    print("Access token saved to: " + green(path))

    return user