Ejemplo n.º 1
0
def create_auth(session, user_agent, app_token, auth_array, max_auth=2):
    me_api = []
    auth_count = 1
    auth_version = "(V1)"
    count = 1
    try:
        auth_id = auth_array["auth_id"]
        auth_cookies = [
            {
                'name': 'auth_id',
                'value': auth_id
            },
            {
                'name': 'sess',
                'value': auth_array["sess"]
            },
            {
                'name': 'auth_hash',
                'value': auth_array["auth_hash"]
            },
            {
                'name': 'auth_uniq_' + auth_id,
                'value': auth_array["auth_uniq_"]
            },
            {
                'name': 'fp',
                'value': auth_array["fp"]
            },
        ]
        while auth_count < max_auth + 1:
            if auth_count == 2:
                auth_version = "(V2)"
                if auth_array["sess"]:
                    del auth_cookies[2]
                count = 1
            print("Auth " + auth_version)
            sess = auth_array["sess"]
            session.headers = {
                'User-Agent': user_agent,
                'Referer': 'https://onlyfans.com/'
            }
            if auth_array["sess"]:
                found = False
                for auth_cookie in auth_cookies:
                    if auth_array["sess"] == auth_cookie["value"]:
                        found = True
                        break
                if not found:
                    auth_cookies.append({
                        'name': 'sess',
                        'value': auth_array["sess"],
                        'domain': '.onlyfans.com'
                    })
            for auth_cookie in auth_cookies:
                session.cookies.set(**auth_cookie)

            max_count = 10
            while count < 11:
                print("Auth Attempt " + str(count) + "/" + str(max_count))
                link = "https://onlyfans.com/api2/v2/users/customer?app-token=" + app_token
                a = [session, link, sess, user_agent]
                session = create_sign(*a)
                r = json_request(session, link)
                count += 1
                if not r:
                    continue
                me_api = r

                def resolve_auth(r):
                    if 'error' in r:
                        error = r["error"]
                        error_message = r["error"]["message"]
                        error_code = error["code"]
                        if error_code == 0:
                            print(error_message)
                        if error_code == 101:
                            error_message = "Blocked by 2FA."
                            print(error_message)
                            if auth_array["support_2fa"]:
                                link = "https://onlyfans.com/api2/v2/users/otp?app-token=" + app_token
                                count = 1
                                max_count = 3
                                while count < max_count + 1:
                                    print("2FA Attempt " + str(count) + "/" +
                                          str(max_count))
                                    code = input("Enter 2FA Code\n")
                                    data = {'code': code, 'rememberMe': True}
                                    r = json_request(session,
                                                     link,
                                                     "PUT",
                                                     data=data)
                                    if "error" in r:
                                        count += 1
                                    else:
                                        print("Success")
                                        return [True, r]
                        return [False, r["error"]["message"]]

                if "name" not in r:
                    result = resolve_auth(r)
                    if not result[0]:
                        error_message = result[1]
                        if "token" in error_message:
                            break
                        if "Code wrong" in error_message:
                            break
                        continue
                    else:
                        continue
                print("Welcome " + r["name"])
                option_string = "username or profile link"
                link = "https://onlyfans.com/api2/v2/subscriptions/count/all?app-token=" + app_token
                r = json_request(session, link)
                if not r:
                    break
                array = dict()
                array["session"] = session
                array["option_string"] = option_string
                array["subscriber_count"] = r["subscriptions"]["active"]
                array["me_api"] = me_api
                return array
            auth_count += 1
    except Exception as e:
        log_error.exception(e)
        # input("Enter to continue")
    array = dict()
    array["session"] = None
    array["me_api"] = me_api
    return array
Ejemplo n.º 2
0
def create_auth(sessions, user_agent, auth_array, max_auth=2):
    me_api = []
    auth_count = 1
    auth_version = "(V1)"
    count = 1
    try:
        auth_cookies = []
        while auth_count < max_auth + 1:
            if auth_count == 2:
                auth_version = "(V2)"
                if auth_array["sess"]:
                    del auth_cookies[2]
                count = 1
            print("Auth " + auth_version)
            sess = auth_array["sess"]
            for session in sessions:
                session.headers = {
                    'User-Agent': user_agent,
                    'Referer': 'https://stars.avn.com/'
                }
                if auth_array["sess"]:
                    found = False
                    for auth_cookie in auth_cookies:
                        if auth_array["sess"] == auth_cookie["value"]:
                            found = True
                            break
                    if not found:
                        auth_cookies.append({
                            'name': 'sess',
                            'value': auth_array["sess"],
                            'domain': '.stars.avn.com'
                        })
                for auth_cookie in auth_cookies:
                    session.cookies.set(**auth_cookie)

            max_count = 10
            while count < 11:
                print("Auth Attempt " + str(count) + "/" + str(max_count))
                link = "https://stars.avn.com/api2/v2/users/me"
                for session in sessions:
                    a = [session, link, sess, user_agent]
                    session = main_helper.create_sign(*a)
                session = sessions[0]
                r = main_helper.json_request(session, link)
                count += 1
                if not r:
                    auth_cookies = []
                    continue
                me_api = r

                def resolve_auth(r):
                    if 'error' in r:
                        error = r["error"]
                        error_message = r["error"]["message"]
                        error_code = error["code"]
                        if error_code == 0:
                            print(error_message)
                        if error_code == 101:
                            error_message = "Blocked by 2FA."
                            print(error_message)
                        return [False, r["error"]["message"]]

                if "name" not in r:
                    result = resolve_auth(r)
                    if not result[0]:
                        error_message = result[1]
                        if "token" in error_message:
                            break
                        if "Code wrong" in error_message:
                            break
                        continue
                    else:
                        continue
                print("Welcome " + r["name"])
                option_string = "username or profile link"
                array = dict()
                array["sessions"] = sessions
                array["option_string"] = option_string
                array["subscriber_count"] = r["followingCount"]
                array["me_api"] = me_api
                return array
            auth_count += 1
    except Exception as e:
        main_helper.log_error.exception(e)
    array = dict()
    array["sessions"] = None
    array["me_api"] = me_api
    return array