1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to get auth token from 2fa Ubisoft login?

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 05:53.

  1. Stack

    Stack Membro Participativo

    I'm trying to get the auth token from a 2fa Ubisoft login but can't figure out how to get it since I just keep bypassing 2fa and getting a non 2fa auth token. I made another one that gave me a twoFactorAuthenticationTicket but still this wasn't a token from a login using 2fa.

    This is the code I tried just made into its own script for testing.

    import requests
    import base64
    import json

    def get_user_headers():
    name_email = input("Enter your Ubisoft email: ")
    name_password = input("Enter your Ubisoft password: ")
    login_url = "https://public-ubiservices.ubi.com/v3/profiles/sessions"

    # Logging in to account with name
    name_account = name_email + ':' + name_password
    name_user = name_account.encode('ascii')
    name_auth = base64.b64encode(name_user).decode('ascii')

    headers = {
    'Authorization': 'Basic ' + name_auth,
    'Ubi-AppId': '3168428b-77ba-4381-b85f-a499e8e92290',
    'Ubi-RequestedPlatformType': 'uplay',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
    'Referer': 'https://connect.ubisoft.com/'
    }

    name_payload = {
    'rememberMe': 'false'
    }

    name_r = requests.post(login_url, headers=headers, json=name_payload)

    if name_r.status_code == 200:
    name_res = name_r.json()
    if 'ticket' in name_res:
    name_auth_token = name_res['ticket']
    name_sessionid = name_res['sessionId']

    # Update headers with correct Authorization and Ubi-SessionId
    headers['Authorization'] = 'Ubi_v1 t=' + name_auth_token
    headers['Ubi-SessionId'] = name_sessionid

    print("\nLogin successful!")
    print(f"Authentication Token: {name_auth_token}")
    print(f"Session ID: {name_sessionid}")
    print("\nFull response:")
    print(json.dumps(name_res, indent=2))

    return headers

    elif 'twoFactorAuthenticationTicket' in name_res:
    while True:
    headers["Authorization"] = 'ubi_2fa_v1 t=' + name_res['twoFactorAuthenticationTicket']
    headers["Ubi-2FACode"] = input('Enter Two Step Code: ')
    swap_t = requests.post(login_url, headers=headers, json={"trustedDevice": None})
    if swap_t.status_code == 200:
    name_res = swap_t.json()
    name_auth_token = name_res['ticket']
    name_sessionid = name_res['sessionId']

    # Update headers with correct Authorization and Ubi-SessionId
    headers['Authorization'] = 'Ubi_v1 t=' + name_auth_token
    headers['Ubi-SessionId'] = name_sessionid

    print("\nTwo-factor authentication successful!")
    print(f"Authentication Token: {name_auth_token}")
    print(f"Session ID: {name_sessionid}")
    print("\nFull response:")
    print(json.dumps(name_res, indent=2))

    return headers

    elif swap_t.status_code == 400 and 'The two factor authentication code' in swap_t.text:
    print("Invalid two factor authentication code. Please try again.")
    continue
    else:
    print(f"Error: Unable to login. Status Code: {name_r.status_code}. Response: {name_r.text}")
    return None

    if __name__ == "__main__":
    headers = get_user_headers()
    if headers:
    print("\nFinal headers:")
    print(json.dumps(headers, indent=2))
    else:
    print("Login failed.")````

    Continue reading...

Compartilhe esta Página