initstring / linkedin2username

OSINT Tool: Generate username lists for companies on LinkedIn
MIT License
1.25k stars 185 forks source link

Implement Selenium WebDriver for Auth #65

Closed initstring closed 1 year ago

initstring commented 1 year ago

Maintaining the login function is a cat/mouse game. Having Selenium launch a browser, allowing the user to login there, and then closing it to get the cookies would reduce a lot of pain and troubleshooting.

This would solve most issues that get opened, and also support 2FA.

The existing login() function could be reduced to something like this:

def login():
    """Creates a new authenticated session.

    This now uses Selenium because I got very tired playing cat/mouse
    with LinkedIn's login process.
    """
    driver = webdriver.Firefox()
    driver.get("https://linkedin.com/login")

    # Pause until the user lets us know the session is good.
    input("Press Enter after you've logged in...")
    selenium_cookies = driver.get_cookies()
    driver.quit()

    # Initialize and return a requests session
    session = requests.Session()
    for cookie in selenium_cookies:
        session.cookies.set(cookie['name'], cookie['value'])

    return session

I'd also need to remove the username and password args.

I tried to test this just now, but ran into issues with Selenium and my Linux VM - probably either because it was Ubuntu using snaps as browsers, or because it was ARM64.

I can try to come back and test this later, but I am very open to help if someone else wants to give it a try.

initstring commented 1 year ago

This is working in https://github.com/initstring/linkedin2username/pull/66.

Tested on MacOS ARM64, should also work in Windows x86/64, Windows ARM64, and Linux x86/64. I understand Selenium is not fully working on Linux ARM64, which may be an issue.