Skip to content

Feature: add QR code login for unauthenticated devices - #185

Open
mvsrcdst wants to merge 1 commit into
Swiftgram:masterfrom
mvsrcdst:feature/qr-login
Open

Feature: add QR code login for unauthenticated devices#185
mvsrcdst wants to merge 1 commit into
Swiftgram:masterfrom
mvsrcdst:feature/qr-login

Conversation

@mvsrcdst

@mvsrcdst mvsrcdst commented Jul 23, 2026

Copy link
Copy Markdown

Motivation

The official Telegram bot stopped sending me a login code entirely: no error, no way back in. Digging through AuthorizationSequencePhoneEntryControllerNode for an existing escape hatch, I found a dead debug hook (#if DEBUG && false, tap-to-reveal-QR gesture on a raw ASImageNode) that already exported a login token but never rendered anything scannable. Built that into a real QR-login flow: an already-authorized device scans it and bypasses code delivery entirely.

Official QR login only runs the other direction (unauthenticated Desktop/Web scanned by an authenticated mobile app).

Summary

The old debug hook only exported a token and drew it into a raw image view, nothing around it actually worked, so I built out the rest: proper error handling and a clean dismiss on the QR screen, and carried the account through correctly after a DC migration so the password step isn't left broken.

Along the way I ran into AUTH_KEY_UNREGISTERED/AUTH_TOKEN_EXPIRED: log in via QR, log out, log back in, and the 2FA password check (or the token import) fails with this error. Real logs showed it's just a short server-side race: the auth key from the DC migration isn't recognized yet, and it clears up in 1-2 seconds if you simply retry. So instead of showing an error and making the user start over, the app now retries that quietly in the background: on the QR screen it silently shows a fresh code, and on the password screen it redoes the login and resubmits the same password automatically. The user only ever sees an alert if that genuinely doesn't work out after a several tries.

Screenshots

Onboarding screen with no QR icon image
Login screen with QR icon image
QR code screen image
Password prompt with close button image
QR code expires but password sent image

Testing

  • Tested on iOS Simulator 18.6/26.5
  • Onboarding screen has no QR icon, Login screen does, QR button works in "Add Account" too
  • Open/close QR screen mid-flow: background loop stops cleanly, token auto-refreshes in place before expiry
  • 2FA happy-path scan + login: 2FA prompt after scan with no dead QR/password screen, back button works
  • No-2FA happy-path scan + login
  • QR code expires but password sent: got alert and auto-back to Login screen to renew QR by the button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant