qrlogin

package
v0.116.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 10 Imported by: 8

Documentation

Overview

Package qrlogin provides QR login flow implementation.

See https://core.telegram.org/api/qr-login.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptQR

func AcceptQR(ctx context.Context, raw *tg.Client, t Token) (*tg.Authorization, error)

AcceptQR accepts given token.

See https://core.telegram.org/api/qr-login#accepting-a-login-token.

Types

type LoggedIn

type LoggedIn <-chan struct{}

LoggedIn is signal channel to notify about tg.UpdateLoginToken.

func OnLoginToken

func OnLoginToken(d interface {
	OnLoginToken(tg.LoginTokenHandler)
},
) LoggedIn

OnLoginToken sets handler for given dispatcher and returns signal channel.

type MigrationNeededError

type MigrationNeededError struct {
	MigrateTo *tg.AuthLoginTokenMigrateTo

	// Tried indicates that the migration was attempted.
	//
	// Deprecated: do not use. QR login uses migrate function passed via
	// options.
	Tried bool
}

MigrationNeededError reports that Telegram requested DC migration to continue login.

func (*MigrationNeededError) Error

func (m *MigrationNeededError) Error() string

Error implements error.

type Options

type Options struct {
	Migrate func(ctx context.Context, dcID int) error
	Clock   clock.Clock
}

Options of QR.

type QR

type QR struct {
	// contains filtered or unexported fields
}

QR implements Telegram QR login flow.

func NewQR

func NewQR(api *tg.Client, appID int, appHash string, opts Options) QR

NewQR creates new QR

func (QR) Accept

func (q QR) Accept(ctx context.Context, t Token) (*tg.Authorization, error)

Accept accepts given token.

See https://core.telegram.org/api/qr-login#accepting-a-login-token.

func (QR) Auth

func (q QR) Auth(
	ctx context.Context,
	loggedIn LoggedIn,
	show func(ctx context.Context, token Token) error,
	exceptIDs ...int64,
) (*tg.AuthAuthorization, error)

Auth generates new QR login token, shows it and awaits acceptation.

NB: Show callback may be called more than once if QR expires.

func (QR) Export

func (q QR) Export(ctx context.Context, exceptIDs ...int64) (Token, error)

Export exports new login token.

See https://core.telegram.org/api/qr-login#exporting-a-login-token.

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token represents Telegram QR Login token.

func NewToken

func NewToken(token []byte, expires int) Token

NewToken creates new Token.

func ParseTokenURL

func ParseTokenURL(u string) (Token, error)

ParseTokenURL creates Token from given URL.

func (Token) Expires

func (t Token) Expires() time.Time

Expires returns token expiration time.

func (Token) Image

func (t Token) Image(level qr.Level) (image.Image, error)

Image returns QR image.

func (Token) String

func (t Token) String() string

String implements fmt.Stringer.

func (Token) URL

func (t Token) URL() string

URL returns login URL.

See https://core.telegram.org/api/qr-login#exporting-a-login-token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL