Skip to content
TGWAY
Channels & Bots STEP 80 / 99

QR Login in the Telegram API

Add QR login to a Telegram API app: exportLoginToken, a tg://login QR code that refreshes before expiry, updateLoginToken, data center moves and 2FA.

  • Applies toDevelopers
  • LevelL4
  • Reading time3 min
  • Verified

The short answer

  1. 1Show the exportLoginToken token as a tg://login QR code.
  2. 2Tokens expire quickly; keep replacing the QR code while the screen is open.
  3. 3On updateLoginToken call exportLoginToken again to get success or a data center move.
In this article
  1. What QR login is
  2. The steps in your app (the side that logs in)
  3. The scanning side (the phone)
  4. Where it usually gets stuck
  5. FAQ
  6. At a glance

What QR login is

Instead of typing a phone number and a code into a desktop or web app, the user scans a QR code on the screen with Telegram on a phone that is already logged in. If your app supports this, users never wait for a code. How it looks to users is in logging in to Telegram Desktop with a QR code.

The steps in your app (the side that logs in)

  1. Call auth.exportLoginToken with your api_id and api_hash. If the app already has other accounts logged in, pass their IDs so they are excluded. The server returns a token and an expiry time.
  2. Encode the token as base64url, build a tg://login?token=… address, and show it on screen as a QR code.
  3. The token expires quickly. Before the expiry time in the reply, call exportLoginToken again and replace the QR code, for as long as the screen is open.
  4. When the user scans and approves it on the phone, your app receives an updateLoginToken update. Call exportLoginToken once more.
  5. If the answer is success (loginTokenSuccess), you are logged in. If it tells you to move to another data center (loginTokenMigrateTo), connect to that data center and finish with auth.importLoginToken; see data centers and _MIGRATE errors.

If the account has Two-Step Verification, SESSION_PASSWORD_NEEDED arrives at this point and you continue with the password check; see the user login flow.

The scanning side (the phone)

An official app that scans the code calls auth.acceptLoginToken with that token to approve the login. If your own app offers "approve a login on another device", this is the method you use. Before approving, always show the user which app is trying to log in, from which device and from where.

Where it usually gets stuck

SymptomCause and fix
The user scans and nothing happensThe QR code had already expired. Make sure you replace it before the expiry time
Approved, but login never completesYou did not call exportLoginToken again after updateLoginToken
Told to move to another data centerCall importLoginToken on that data center; it needs a new connection
Token error (400)Expired or already used token; create a new QR code

FAQ

How does QR login work in the Telegram API?

Your app gets a token from auth.exportLoginToken and shows it as a tg://login QR code; a logged-in phone scans it and approves with auth.acceptLoginToken.

Why does scanning my QR code do nothing?

The token had expired. Call exportLoginToken again before the expiry time and refresh the QR code.

What if the account has Two-Step Verification?

After the QR step you get SESSION_PASSWORD_NEEDED and must complete the password check with SRP.

Sources

Summary

At a glance

QR Login in the Telegram API — at a glance illustration
  1. 1Show

    base64url token in tg://login?token=…, refreshed before expiry.

  2. 2Finish

    loginTokenSuccess, or loginTokenMigrateTo then importLoginToken.

  3. 3Approve

    acceptLoginToken; show app, device and location first.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›