-
Notifications
You must be signed in to change notification settings - Fork 27
/
auth.go
70 lines (55 loc) · 1.34 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
59
60
61
62
63
64
65
66
67
68
69
70
package mtproto
import (
"errors"
"fmt"
)
func (m *MTProto) AuthSendCode(phonenumber string) (*TL_auth_sentCode, error) {
var authSentCode TL_auth_sentCode
tl, err := m.InvokeSync(TL_auth_sendCode{
Allow_flashcall: false,
Phone_number: phonenumber,
Current_number: TL_boolTrue{},
Api_id: m.id,
Api_hash: m.hash,
})
if err != nil {
return nil, err
}
switch (*tl).(type) {
case TL_auth_sentCode:
authSentCode = (*tl).(TL_auth_sentCode)
default:
return nil, fmt.Errorf("Got: %T", *tl)
}
return &authSentCode, nil
}
func (m *MTProto) AuthSignIn(phoneNumber, phoneCode, phoneCodeHash string) (*TL_auth_authorization, error) {
if phoneNumber == "" || phoneCode == "" || phoneCodeHash == "" {
return nil, errors.New("MRProto::AuthSignIn one of function parameters is empty")
}
tl, err := m.InvokeSync(TL_auth_signIn{
Phone_number: phoneNumber,
Phone_code_hash: phoneCodeHash,
Phone_code: phoneCode,
})
if err != nil {
return nil, err
}
auth, ok := (*tl).(TL_auth_authorization)
if !ok {
return nil, fmt.Errorf("RPC: %#v", *tl)
}
return &auth, nil
}
func (m *MTProto) AuthLogOut() (bool, error) {
var result bool
tl, err := m.InvokeSync(TL_auth_logOut{})
if err != nil {
return result, err
}
result, err = ToBool(*tl)
if err != nil {
return result, err
}
return result, err
}