Skip to content

Commit

Permalink
docs(readme): update auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 24, 2020
1 parent 2d72fe4 commit ff9ea48
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,23 @@ You can see `cmd/gotdecho` for echo bot example.

#### User

You can use `td/telegram/tgflow` package to deal with user auth.
You can use `td/telegram/AuthFlow` to simplify user authentication flow.

```go
codePrompt := func(ctx context.Context) (string, error) {
// Safely get authentication code from terminal here,
// like in https://play.golang.org/p/l-9IP1mrhA
return code, nil
// NB: Use "golang.org/x/crypto/ssh/terminal" to prompt password.
fmt.Print("Enter code: ")
code, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return "", err
}
return strings.TrimSpace(code), nil
}
// This will setup and perform authentication flow.
// If account does not require 2FA password, use tgflow.CodeOnlyAuth
// instead of tgflow.ConstantAuth.
if err := tgflow.NewAuth(
tgflow.ConstantAuth(phone, password, tgflow.CodeAuthenticatorFunc(codePrompt)),
// If account does not require 2FA password, use telegram.CodeOnlyAuth
// instead of telegram.ConstantAuth.
if err := telegram.NewAuth(
telegram.ConstantAuth(phone, password, telegram.CodeAuthenticatorFunc(codePrompt)),
telegram.SendCodeOptions{},
).Run(ctx, client); err != nil {
panic(err)
Expand Down

0 comments on commit ff9ea48

Please sign in to comment.