Jayapraveen / INE-courses-downloader

Python Script to download coures from INE.com website for personal and educational use
GNU General Public License v3.0
37 stars 19 forks source link

Access token entered is faulty. Check for and correct errors! #34

Open Gamra01 opened 2 years ago

Gamra01 commented 2 years ago

Access token entered is faulty. Check for and correct errors!

ghost commented 2 years ago

you can bypass it for now but the refresh token needs fixed in login() and access_token_refetch()

after 4hrs the token will expire. this is not a fix just a bypass until refresh-token is fixed

in login() change ["Refresh"] to ["Bearer"]

current: refresh_token = login_data["data"]["tokens"]["data"]["Refresh"]

bypass: (until resolved) refresh_token = login_data["data"]["tokens"]["data"]["Bearer"]

ghost commented 2 years ago

old code:

def login():
    global access_token
    global refresh_token
    host = "uaa.ine.com"
    header = {"Host": host,"Origin": origin,"Referer": referer,"User-Agent": user_agent,"Accept": accept,"X-Requested-With": x_requested_with,"Accept-Encoding": accept_encodings,"sec-fetch-mode": sec_fetch_mode,"sec-fetch-dest": sec_fetch_dest,"Content-Type": content_type}
    user_name = input("Enter your Username: ")
    password = getpass.getpass(prompt="Enter your Password: \n")
    login_data = {"username": user_name,"password": password}
    login_data = json.dumps(login_data)
    login_data = requests.post(login_url,headers = header,data = login_data)
    if(login_data.status_code == 200):
        login_data = json.loads(login_data.text)
        access_token = login_data["data"]["tokens"]["data"]["Bearer"]
        refresh_token = login_data["data"]["tokens"]["data"]["Refresh"]
        with open(token_path,'w') as fp:
            tokens = {"access_token": access_token,"refresh_token": refresh_token}
            fp.write(json.dumps(tokens))
            access_token = "Bearer "+ access_token
            auth_check()
    elif(login_data.status_code == 403):
        print("Username or password is incorrect\n ")
        option = int(input("Choose from the following options:\n1.Relogin\n2.Exit\n"))
        if(option == 1):
            login()
        else:
            exit()

updatd code:


def login():
    global access_token
    global refresh_token
    host = "uaa.ine.com"
    header = {"Host": host,"Origin": origin,"Referer": referer,"User-Agent": user_agent,"Accept": accept,"X-Requested-With": x_requested_with,"Accept-Encoding": accept_encodings,"sec-fetch-mode": sec_fetch_mode,"sec-fetch-dest": sec_fetch_dest,"Content-Type": content_type}
    user_name = input("Enter your Username: ")
    password = getpass.getpass(prompt="Enter your Password: \n")
    login_data = {"username": user_name,"password": password}
    login_data = json.dumps(login_data)
    login_data = requests.post(login_url,headers = header,data = login_data)
    if(login_data.status_code == 200):
        login_data = json.loads(login_data.text)
        access_token = login_data["data"]["tokens"]["data"]["Bearer"]
        refresh_token = login_data["data"]["tokens"]["data"]["Bearer"]
        with open(token_path,'w') as fp:
            tokens = {"access_token": access_token,"refresh_token": refresh_token}
            fp.write(json.dumps(tokens))
            access_token = "Bearer "+ access_token
            auth_check()
    elif(login_data.status_code == 403):
        print("Username or password is incorrect\n ")
        option = int(input("Choose from the following options:\n1.Relogin\n2.Exit\n"))
        if(option == 1):
            login()
        else:
            exit()

refresh has been removed from the json

ghost commented 2 years ago

if you want to fix refresh token also do this

add these headers in #headers (line 43 start) don't delete the existing headers already there.

everything with _2 on the end need to add


#headers
accept = "application/json, text/plain, */*"
x_requested_with = "com.my.ine"
sec_fetch_site = "cross-site"
sec_fetch_site_2 = "same-site"
sec_fetch_mode = "cors"
sec_fetch_dest = "empty"
content_type = "application/json;charset=UTF-8"
content_type_2 = "application/x-www-form-urlencoded"
user_agent = "Mozilla/5.0 (Linux; Android 6.0;PIXEL XL Build/INE) Mobile Safari/537.29"
referer = "https://my.ine.com"
origin = "file://"
accept_encodings = "gzip, deflate, br"
accept_encodings_2 = "gzip, deflate"
#endpoints

then change the access_token_refetch function with this updated one I made

def access_token_refetch():
    global access_token
    global refresh_token
    host = "uaa.ine.com"
    header = {"Host": host,"Origin": referer,"Referer": referer,"Authorization": access_token,"User-Agent": user_agent,"Accept": accept,"X-Requested-With": x_requested_with,"Accept-Encoding": accept_encodings_2,"sec-fetch-mode": sec_fetch_mode,"sec-fetch-dest": sec_fetch_dest,"Content-Type": content_type_2}
    refresh_data = json.dumps({"refresh_token":refresh_token})
    out = requests.post(refresh_token_url, headers = header)
    #out = requests.post(refresh_token_url, data = refresh_data , headers = header)
    if(out.status_code == 200):
        out = json.loads(out.text)
        access_token = out["data"]["tokens"]["data"]["Bearer"]
        refresh_token = out["data"]["tokens"]["data"]["Bearer"]
        with open(token_path,'w') as fp:
            tokens = {"access_token": access_token,"refresh_token": refresh_token}
            fp.write(json.dumps(tokens))
        access_token = "Bearer "+ access_token
        print("Got new tokens")
    elif(out.status_code == 401):
        relogin = int(input("Failure, Please choose from the following options\n1.Login\n2.Recheck for updated tokens(after updating the tokens in the file)\n3.Exit\n"))
        if(relogin == 1):
            login()
        elif(relogin == 2):
            auth_check()
        elif(relogin == 3):
            exit()

now token will refresh again ;D enjoy!

ghost commented 2 years ago

**update the have access function also

replace old code**

def course_has_access(course):
    for passes in range(len(course["access"]["related_passes"]) -1 ,0,-1):
        boolean =  True if course["access"]["related_passes"][passes]["name"] in access_pass else False
        if(boolean):
            break
    return boolean

with updated function

def course_has_access(course):
    global have_access
    have_access = False
    for passes in range(len(course["access"]["related_passes"])):
        try:
            have_access = True if course["access"]["related_passes"][passes]["name"] in access_pass else True
            if have_access == False:
                have_access = True if course["access"]["related_passes"][passes][0]["name"] in access_pass else True
        except:
            try:
                have_access = True if course["access"]["related_passes"][passes][0]["name"] in access_pass else True
            except:
                if(have_access):
                    break
    return have_access
Andre-pwn commented 1 year ago

Still doesn't work after changes, token faulty

Extremalzhez commented 1 year ago

Is anyone fixed this issue? I did everything above but still the script won’t work