def getGoogleAccountTokenFromAuth():

    b64_key_7_3_29 = (
        b"AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3"
        b"iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pK"
        b"RI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/"
        b"6rmf5AAAAAwEAAQ==")

    android_key_7_3_29 = google.key_from_b64(b64_key_7_3_29)
    encpass = google.signature(gmail, passw, android_key_7_3_29)
    payload = {
        'Email': gmail,
        'EncryptedPasswd': encpass,
        'app': client_pkg,
        'client_sig': client_sig,
        'parentAndroidId': devid
    }
    request = requests.post('https://android.clients.google.com/auth',
                            data=payload)
    token = re.search('Token=(.*?)\n', request.text)

    if token:
        return token.group(1)
    else:
        quit(request.text)
Example #2
0
def getGoogleAccountTokenFromAuth():
    b64_key_7_3_29 = (
        b"AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ=="
    )
    android_key_7_3_29 = google.key_from_b64(b64_key_7_3_29)
    encpass = google.signature(gmail, passw, android_key_7_3_29)
    pkg = 'com.google.android.gms'  # APK package name Google Play Services
    sig = '38918a453d07199354f8b19af05ec6562ced5788'  # APK Google Play Services certificate fingerprint SHA-1
    payload = {
        'Email': gmail,
        'EncryptedPasswd': encpass,
        'app': pkg,
        'client_sig': sig,
        'parentAndroidId': devid
    }
    request = requests.post(auth_url, data=payload, headers=header)
    print("Requesting Auth for Google....")
    #print(request.text)
    token = re.search('Token=(.*)', request.text)
    if token:
        print("Granted\n")
        return token.group(1)
    else:
        print("Failed\n")
        print(request.text)
        if "BadAuthentication" in request.text:
            print("\n   Workaround\n-----------------")
            print(
                "1. Check that your email and password are correct in the settings file, if so change your google password and try again.\n"
                "2. Your are using a old python version. Works > 3.7.7.\n"
                "3. Update requirements, use in a terminal: 'pip3 install --upgrade -r ./doc/requirements.txt' or 'pip install --upgrade -r ./doc/requirements.txt"
            )

        elif "NeedsBrowser" in request.text:
            print("\n   Workaround\n-----------------")
            print(
                "1. Maybe you need unlock captcha in your account, If you request it, log in to your browser and then click here, https://accounts.google.com/DisplayUnlockCaptcha."
            )
            print(
                "2. Or you have double factor authentication enabled, so disable it in this URL: https://myaccount.google.com/security"
            )
            print(
                "3. If you want to use 2FA, you will have to go to the URL: https://myaccount.google.com/apppasswords\n"
                "   Then select Application: Other. Write down: Whapa, and a password will be display, then you must write the password in your settings.cfg."
            )

        elif "DeviceManagementRequiredOrSyncDisabled" in request.text:
            print("\n   Workaround\n-----------------")
            print(
                "1. You are using a GSuite account.  The reason for this is, that for this google-apps account, the enforcement of policies on mobile clients is enabled in admin console (enforce_android_policy).\n"
                "   If you disable this in admin-console, the authentication works."
            )

        quit()