EdupageAPI / edupage-api

A python library for accessing your Edupage account
https://edupageapi.github.io/edupage-api/
GNU General Public License v3.0
66 stars 13 forks source link

Implement support for 2fa (Closes #74) #75

Closed ivanhrabcak closed 6 months ago

ivanhrabcak commented 6 months ago

I have tried to design the API so that existing code and control flow is not broken by this change.


If 2fa is not set up, this basic example will work as expected:

from edupage_api import Edupage

edupage = Edupage()

try:
    edupage.login("Username", "Password", "Your school's subdomain")
except BadCredentialsException:
    print("Wrong username or password!")
except LoginDataParsingException:
    print("Try again or open an issue!")

You have successfully logged in.


If 2fa is set up, you can login in a similar way — note the second_factor variable:

from edupage_api import Edupage

edupage = Edupage()

try:
    second_factor = edupage.login("Username", "Password", "Your school's subdomain")
    # or
    second_factor = edupage.login_auto("Username", "Password")
except BadCredentialsException:
    print("Wrong username or password!")
except LoginDataParsingException:
    print("Try again or open an issue!")

This will return the TwoFactorLogin object, which can be used to complete the login, or to resend the 2fa notification.


There are two ways to complete the login process:

By confirming through the mobile application:

while not second_factor.is_confirmed():
    time.sleep(0.5)

second_factor.finish()

# You are now logged in!

By confirming the code (from email or mobile app):

second_factor.finish_with_code("123456")

# You are now logged in!