Skip to content

Commit

Permalink
second fix for qr code login url creation
Browse files Browse the repository at this point in the history
The mobile app does some crazy things with the URL. I think most of it
just boils down to picking the right space. It does it automatically by
matching the URL from the QR code with a list of spaces that it fetches
from PRONOTE. Otherwise it prompts the user to choose.

We're just prepending "mobile." if the URL doesn't have the prefix.

closes #299 (for real this time)
  • Loading branch information
bain3 committed Jul 5, 2024
1 parent e25e194 commit 9b09833
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions pronotepy/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,28 @@ def qrcode_login(cls: Type[T], qr_code: dict, pin: str, uuid: str) -> T:
except CryptoError as ex:
raise QRCodeDecryptError("invalid confirmation code") from ex

# Add magic parameters at the end of the URL. You can find them in a
# file called "ObjetCommMessage.js" in the connection method when you
# decompile the mobile APK.
url: str = urlunparse(
urlparse(qr_code["url"])._replace(
query="fd=1&bydlg=A6ABB224-12DD-4E31-AD3E-8A39A1C2C335&login=true"
)
url = urlparse(qr_code["url"])

# The app would query the server for all the available spaces and find
# a space by checking if the last part of the URL matches one of the
# space URLs. eg. "/pronote/parent.html" would match "mobile.parent.html"
# (info url: <pronote root>/InfoMobileApp.json?id=0D264427-EEFC-4810-A9E9-346942A862A4)

# We're gonna try the shorter route of just prepending "mobile." if it
# isn't there already
parts = url.path.split("/")
if not parts[-1].startswith("mobile."):
parts[-1] = "mobile." + parts[-1]

# Reconstruct the url and add magic parameters at the end of the URL.
# You can find them in a file called "ObjetCommMessage.js" in the
# connection method when you decompile the mobile APK.
fixed_url = url._replace(
path="/".join(parts),
query="fd=1&bydlg=A6ABB224-12DD-4E31-AD3E-8A39A1C2C335&login=true",
)

return cls(url, login, jeton, mode="qr_code", uuid=uuid)
return cls(urlunparse(fixed_url), login, jeton, mode="qr_code", uuid=uuid)

@classmethod
def token_login(
Expand Down

0 comments on commit 9b09833

Please sign in to comment.