Involved Source Filesaccept.goerrors.gooptions.go Package qrlogin provides QR login flow implementation.
See https://core.telegram.org/api/qr-login.token.go
Package-Level Type Names (total 6, all are exported)
/* sort exporteds by: | */
ExportResult is a result of exporting login token.
Exactly one field is set. Authorization is set for auth.loginTokenSuccess: token was already
accepted and login is complete. MigrateTo is set for auth.loginTokenMigrateTo: login should be
completed via auth.importLoginToken on given DC. Token is set for auth.loginToken: show it and wait for acceptance.
func QR.ExportResult(ctx context.Context, exceptIDs ...int64) (ExportResult, error)
MigrationNeededError reports that Telegram requested DC migration to continue login.MigrateTo*tg.AuthLoginTokenMigrateTo Tried indicates that the migration was attempted.
Deprecated: do not use. QR login uses migrate function passed via
options. Error implements error.
*MigrationNeededError : error
Options of QR.Clockclock.ClockMigratefunc(ctx context.Context, dcID int) error Password returns 2FA password of the account (optional).
If set, Import and Auth complete 2FA (auth.checkPassword) when the
account has a password, instead of returning SESSION_PASSWORD_NEEDED.(*Options) setDefaults()
func NewQR(api *tg.Client, appID int, appHash string, opts Options) QR
QR implements Telegram QR login flow.api*tg.ClientappHashstringappIDintclockclock.Clockmigratefunc(ctx context.Context, dcID int) errorpasswordfunc(ctx context.Context) (string, error) Accept accepts given token.
See https://core.telegram.org/api/qr-login#accepting-a-login-token. Auth generates new QR login token, shows it and awaits acceptation.
NB: Show callback may be called more than once if QR expires.
Transient errors of token refresh are retried with backoff.
If the token is accepted by an account of another DC, the login is
completed there via Options.Migrate (as in Import), also when the
acceptance is seen on a token refresh instead of updateLoginToken. Without
Options.Migrate, *MigrationNeededError is returned. Export exports new login token.
If token was already accepted (auth.loginTokenSuccess), Export returns an
empty token and the authorization is discarded; use ExportResult to get it.
If migration is needed, Export returns *MigrationNeededError.
See https://core.telegram.org/api/qr-login#exporting-a-login-token. ExportResult exports new login token, returning authorization if token
was already accepted.
See https://core.telegram.org/api/qr-login#exporting-a-login-token. Import imports accepted token.
If the account has 2FA password and Options.Password is set, the password
is checked, otherwise SESSION_PASSWORD_NEEDED error is returned.
See https://core.telegram.org/api/qr-login#confirming-importing-the-login-token.( QR) checkPassword(ctx context.Context) (*tg.AuthAuthorization, error)( QR) export(ctx context.Context, exceptIDs ...int64) (tg.AuthLoginTokenClass, error) finishMigrated is importMigrated with the 2FA check of Import. importMigrated completes the login of an account on another DC: migrates
to it and imports the token there. It returns *MigrationNeededError if no
migrate function is set.( QR) importToken(ctx context.Context) (*tg.AuthAuthorization, error) needPassword reports whether err requests 2FA password and it can be
provided.
func NewQR(api *tg.Client, appID int, appHash string, opts Options) QR
func github.com/gotd/td/telegram.(*Client).QR() QR
Package-Level Functions (total 7, in which 5 are exported)
AcceptQR accepts given token.
See https://core.telegram.org/api/qr-login#accepting-a-login-token.
NewQR creates new QR
NewToken creates new Token.
OnLoginToken sets handler for given dispatcher and returns signal channel.
The channel is a latch: an update received while nobody is waiting on the
channel (e.g. during show callback or token export) is kept until read.
ParseTokenURL creates Token from given URL.
nextRetryDelay returns backoff delay after prev delay for given error.
retryableExportError reports whether token refresh can be retried after err.
Package-Level Constants (total 3, none are exported)
minRetryDelay and maxRetryDelay bound backoff of token refresh retries.
minTokenWait is the minimum delay before token refresh, protecting
against busy loop if the local clock is ahead of server time.
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.