-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.go
executable file
·58 lines (44 loc) · 1.62 KB
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// AUTOGENERATED - DO NOT EDIT
package tdlib
type AuthFunctions interface {
Authorize() (AuthorizationState, error)
SendPhoneNumber(phoneNumber string) (AuthorizationState, error)
SendAuthCode(code string) (AuthorizationState, error)
SendAuthPassword(password string) (AuthorizationState, error)
}
// Authorize is used to authorize the users
func (client *ClientImpl) Authorize() (AuthorizationState, error) {
state, err := client.GetAuthorizationState()
if err != nil {
return nil, err
}
if state.GetAuthorizationStateEnum() == AuthorizationStateWaitTdlibParametersType {
client.sendTdLibParams()
}
return client.GetAuthorizationState()
}
// SendPhoneNumber sends phone number to tdlib
func (client *ClientImpl) SendPhoneNumber(phoneNumber string) (AuthorizationState, error) {
phoneNumberConfig := PhoneNumberAuthenticationSettings{AllowFlashCall: false, IsCurrentPhoneNumber: false, AllowSmsRetrieverAPI: false}
_, err := client.SetAuthenticationPhoneNumber(phoneNumber, &phoneNumberConfig)
if err != nil {
return nil, err
}
return client.GetAuthorizationState()
}
// SendAuthCode sends auth code to tdlib
func (client *ClientImpl) SendAuthCode(code string) (AuthorizationState, error) {
_, err := client.CheckAuthenticationCode(code)
if err != nil {
return nil, err
}
return client.GetAuthorizationState()
}
// SendAuthPassword sends two-step verification password (user defined)to tdlib
func (client *ClientImpl) SendAuthPassword(password string) (AuthorizationState, error) {
_, err := client.CheckAuthenticationPassword(password)
if err != nil {
return nil, err
}
return client.GetAuthorizationState()
}