forked from wuman/firebase-server-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth_user.go
103 lines (89 loc) · 3.14 KB
/
auth_user.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package firebase
import (
"strconv"
"time"
)
// UserRecord defines the data model for Firebase interface representing a user.
type UserRecord struct {
UID string
DisplayName string
Email string
EmailVerified bool
PhotoURL string
ProviderData []*UserInfo
TokensValidAfterMillis int64 // milliseconds since epoch.
Disabled bool
Metadata *UserMetadata
PhoneNumber string
}
// UserInfo defines the data model for Firebase interface representing a user's info from a third-party
// identity provider such as Google or Facebook.
type UserInfo struct {
UID string
ProviderID string
DisplayName string
PhoneNumber string
Email string
PhotoURL string
}
// UserMetadata defines the data model for Firebase interface representing a user's metadata.
type UserMetadata struct {
CreatedAt time.Time
LastSignedIn time.Time
}
// UserProperties defines the input user properties in a create or edit user API.
//
// Note that user attributes without setup in create actions will remain in default values.
// And attributes without setup in edit actions are remaining unchanged.
type UserProperties map[string]interface{}
// SetUID sets the uid to assign to the newly created user.
// Must be a string between 1 and 128 characters long, inclusive.
// If not provided, a random uid will be automatically generated.
//
// Note that this property takes no effects in update user actions.
func (p UserProperties) SetUID(uid string) UserProperties {
p["uid"] = uid
return p
}
// SetEmail sets the user's primary email. Must be a valid email address.
func (p UserProperties) SetEmail(email string) UserProperties {
p["email"] = email
return p
}
// SetEmailVerified sets whether or not the user's primary email is verified.
func (p UserProperties) SetEmailVerified(emailVerified bool) UserProperties {
p["emailVerified"] = emailVerified
return p
}
// SetPassword sets the user's raw, unhashed password.
// Must be at least six characters long.
func (p UserProperties) SetPassword(password string) UserProperties {
p["password"] = password
return p
}
// SetDisplayName sets the users' display name.
// Only passing an empty string in edit actions removes the display name in the user record.
func (p UserProperties) SetDisplayName(displayName string) UserProperties {
p["displayName"] = displayName
return p
}
// SetPhotoURL sets the user's photo URL.
// Only passing an empty string in edit actions removes the photo URL in the user record.
func (p UserProperties) SetPhotoURL(photoURL string) UserProperties {
p["photoURL"] = photoURL
return p
}
// SetDisabled sets whether or not the user is disabled
func (p UserProperties) SetDisabled(disabled bool) UserProperties {
p["disabled"] = disabled
return p
}
// The user's new primary phone number. Must be a valid E.164 spec compliant phone number.
func (p UserProperties) SetPhoneNumber(phoneNumber string) UserProperties {
p["phoneNumber"] = phoneNumber
return p
}
func (p UserProperties) SetValidSince(valid time.Time) UserProperties {
p["validSince"] = strconv.FormatInt(valid.Unix(), 10)
return p
}