package auth

Import Path
	github.com/gotd/td/telegram/auth (on go.dev)

Dependency Relation
	imports 12 packages, and imported by one package

Involved Source Files Package auth provides authentication on top of tg.Client. bot.go client.go flow.go password.go self.go signup.go status.go user.go
Package-Level Type Names (total 18, in which 13 are exported)
/* sort exporteds by: | */
Client implements Telegram authentication. AcceptTOS accepts version of Terms Of Service. Bot performs bot authentication request. CancelPasswordReset cancels password reset. See https://core.telegram.org/api/srp#password-reset. IfNecessary runs given auth flow if current session is not authorized. Password performs login via secure remote password (aka 2FA). Method can be called after SignIn to provide password if requested. ResetPassword resets cloud password and returns time to wait until reset be performed. If time is zero, password was successfully reset. May return ResetFailedWaitError. See https://core.telegram.org/api/srp#password-reset. SendCode requests code for provided phone number, returning code hash and error if any. Use AuthFlow to reduce boilerplate. This method should be called first in user authentication flow. SignIn performs sign in with provided user phone, code and code hash. If ErrPasswordAuthNeeded is returned, call Password to provide 2FA password. To obtain codeHash, use SendCode. SignUp registers a validated phone number in the system. To obtain codeHash, use SendCode. Use AuthFlow helper to handle authentication flow. Status gets authorization status of client. Test creates and runs auth flow using Test authenticator if current session is not authorized. TestUser creates and runs auth flow using TestUser authenticator if current session is not authorized. UpdatePassword sets new cloud password for this account. See https://core.telegram.org/api/srp#setting-a-new-2fa-password. *Client : FlowClient func NewClient(api *tg.Client, rand io.Reader, appID int, appHash string) *Client func github.com/gotd/td/telegram.(*Client).Auth() *Client
CodeAuthenticator asks user for received authentication code. ( CodeAuthenticator) Code(ctx context.Context, sentCode *tg.AuthSentCode) (string, error) CodeAuthenticatorFunc UserAuthenticator (interface) func CodeOnly(phone string, code CodeAuthenticator) UserAuthenticator func Constant(phone, password string, code CodeAuthenticator) UserAuthenticator func Env(prefix string, code CodeAuthenticator) UserAuthenticator
CodeAuthenticatorFunc is functional wrapper for CodeAuthenticator. Code implements CodeAuthenticator interface. CodeAuthenticatorFunc : CodeAuthenticator
Flow simplifies boilerplate for authentication flow. Auth UserAuthenticator Options SendCodeOptions Run starts authentication flow on client. func NewFlow(auth UserAuthenticator, opt SendCodeOptions) Flow func (*Client).IfNecessary(ctx context.Context, flow Flow) error
FlowClient abstracts telegram client for Flow. ( FlowClient) Password(ctx context.Context, password string) (*tg.AuthAuthorization, error) ( FlowClient) SendCode(ctx context.Context, phone string, options SendCodeOptions) (tg.AuthSentCodeClass, error) ( FlowClient) SignIn(ctx context.Context, phone, code, codeHash string) (*tg.AuthAuthorization, error) ( FlowClient) SignUp(ctx context.Context, s SignUp) (*tg.AuthAuthorization, error) *Client func Flow.Run(ctx context.Context, client FlowClient) error
ResetFailedWaitError reports that you recently requested a password reset that was cancel and need to wait until the specified date before requesting another reset. Result tg.AccountResetPasswordFailedWait Error implements error. Until returns time required to wait. *ResetFailedWaitError : error
SendCodeOptions defines how to send auth code to user. If a token that will be included in eventually sent SMSs is required: required in newer versions of android, to use the android SMS receiver APIs. AllowFlashCall allows phone verification via phone calls. Pass true if the phone number is used on the current device. Ignored if AllowFlashCall is not set. func NewFlow(auth UserAuthenticator, opt SendCodeOptions) Flow func (*Client).SendCode(ctx context.Context, phone string, options SendCodeOptions) (tg.AuthSentCodeClass, error) func FlowClient.SendCode(ctx context.Context, phone string, options SendCodeOptions) (tg.AuthSentCodeClass, error)
SignUp wraps parameters for SignUp. New user first name New user last name SMS-message ID Phone number in the international format func (*Client).SignUp(ctx context.Context, s SignUp) (*tg.AuthAuthorization, error) func FlowClient.SignUp(ctx context.Context, s SignUp) (*tg.AuthAuthorization, error)
SignUpRequired means that log in failed because corresponding account does not exist, so sign up is required. TermsOfService tg.HelpTermsOfService (*SignUpRequired) Error() string Is returns true if err is SignUpRequired. *SignUpRequired : error
Status represents authorization status. Authorized is true if client is authorized. User is current User object. func (*Client).Status(ctx context.Context) (*Status, error)
UpdatePasswordOptions is options structure for UpdatePassword. Hint is new password hint. Password is password callback. If password was requested and Password is nil, ErrPasswordNotProvided error will be returned. func (*Client).UpdatePassword(ctx context.Context, newPassword string, opts UpdatePasswordOptions) error
UserAuthenticator asks user for phone, password and received authentication code. ( UserAuthenticator) AcceptTermsOfService(ctx context.Context, tos tg.HelpTermsOfService) error ( UserAuthenticator) Code(ctx context.Context, sentCode *tg.AuthSentCode) (string, error) ( UserAuthenticator) Password(ctx context.Context) (string, error) ( UserAuthenticator) Phone(ctx context.Context) (string, error) ( UserAuthenticator) SignUp(ctx context.Context) (UserInfo, error) UserAuthenticator : CodeAuthenticator func CodeOnly(phone string, code CodeAuthenticator) UserAuthenticator func Constant(phone, password string, code CodeAuthenticator) UserAuthenticator func Env(prefix string, code CodeAuthenticator) UserAuthenticator func Test(randReader io.Reader, dc int) UserAuthenticator func TestUser(phone string, dc int) UserAuthenticator func NewFlow(auth UserAuthenticator, opt SendCodeOptions) Flow
UserInfo represents user info required for sign up. FirstName string LastName string func UserAuthenticator.SignUp(ctx context.Context) (UserInfo, error)
Package-Level Functions (total 12, in which 11 are exported)
CodeOnly creates UserAuthenticator with constant phone and no password.
Constant creates UserAuthenticator with constant phone and password.
Env creates UserAuthenticator which gets phone and password from environment variables.
IsKeyUnregistered reports whether err is AUTH_KEY_UNREGISTERED error. Deprecated: use IsUnauthorized.
IsUnauthorized reports whether err is 401 UNAUTHORIZED. https://core.telegram.org/api/errors#401-unauthorized
NewClient initializes and returns Telegram authentication client.
NewFlow initializes new authentication flow.
NewPasswordHash computes new password hash to update password. Notice that NewPasswordHash mutates given alg. See https://core.telegram.org/api/srp#setting-a-new-2fa-password.
PasswordHash computes password hash to log in. See https://core.telegram.org/api/srp#checking-the-password-with-srp.
Test returns UserAuthenticator that authenticates via testing credentials. Can be used only with testing server. Will perform sign up if test user is not registered.
TestUser returns UserAuthenticator that authenticates via testing credentials. Uses given phone to sign in/sign up. Can be used only with testing server. Will perform sign up if test user is not registered.
Package-Level Variables (total 4, in which 3 are exported)
ErrPasswordAuthNeeded means that 2FA auth is required. Call Client.Password to provide 2FA password.
ErrPasswordInvalid means that password provided to Password is invalid. Note that telegram does not trim whitespace characters by default, check that provided password is expected and clean whitespaces if needed. You can use strings.TrimSpace(password) for this.
ErrPasswordNotProvided means that password requested by Telegram, but not provided by user.