@@ -21,6 +21,7 @@ import (
21
21
"reflect"
22
22
"regexp"
23
23
"strings"
24
+ "time"
24
25
25
26
"golang.org/x/net/context"
26
27
"google.golang.org/api/identitytoolkit/v3"
@@ -39,6 +40,7 @@ var commonValidators = map[string]func(interface{}) error{
39
40
"password" : validatePassword ,
40
41
"photoUrl" : validatePhotoURL ,
41
42
"localId" : validateUID ,
43
+ "validSince" : func (interface {}) error { return nil }, // Needed for preparePayload.
42
44
}
43
45
44
46
// Create a new interface
@@ -65,6 +67,7 @@ type UserInfo struct {
65
67
}
66
68
67
69
// UserMetadata contains additional metadata associated with a user account.
70
+ // Timestamps are in milliseconds since epoch.
68
71
type UserMetadata struct {
69
72
CreationTimestamp int64
70
73
LastLogInTimestamp int64
@@ -73,11 +76,12 @@ type UserMetadata struct {
73
76
// UserRecord contains metadata associated with a Firebase user account.
74
77
type UserRecord struct {
75
78
* UserInfo
76
- CustomClaims map [string ]interface {}
77
- Disabled bool
78
- EmailVerified bool
79
- ProviderUserInfo []* UserInfo
80
- UserMetadata * UserMetadata
79
+ CustomClaims map [string ]interface {}
80
+ Disabled bool
81
+ EmailVerified bool
82
+ ProviderUserInfo []* UserInfo
83
+ TokensValidAfterMillis int64 // milliseconds since epoch.
84
+ UserMetadata * UserMetadata
81
85
}
82
86
83
87
// ExportedUserRecord is the returned user value used when listing all the users.
@@ -173,6 +177,13 @@ func (u *UserToUpdate) PhoneNumber(phone string) *UserToUpdate { u.set("phoneNum
173
177
// PhotoURL setter.
174
178
func (u * UserToUpdate ) PhotoURL (url string ) * UserToUpdate { u .set ("photoUrl" , url ); return u }
175
179
180
+ // revokeRefreshTokens revokes all refresh tokens for a user by setting the validSince property
181
+ // to the present in epoch seconds.
182
+ func (u * UserToUpdate ) revokeRefreshTokens () * UserToUpdate {
183
+ u .set ("validSince" , time .Now ().Unix ())
184
+ return u
185
+ }
186
+
176
187
// CreateUser creates a new user with the specified properties.
177
188
func (c * Client ) CreateUser (ctx context.Context , user * UserToCreate ) (* UserRecord , error ) {
178
189
uid , err := c .createUser (ctx , user )
@@ -471,7 +482,12 @@ func (u *UserToUpdate) preparePayload(user *identitytoolkit.IdentitytoolkitRelyi
471
482
if err := validate (v ); err != nil {
472
483
return err
473
484
}
474
- reflect .ValueOf (user ).Elem ().FieldByName (strings .Title (key )).SetString (params [key ].(string ))
485
+ f := reflect .ValueOf (user ).Elem ().FieldByName (strings .Title (key ))
486
+ if f .Kind () == reflect .String {
487
+ f .SetString (params [key ].(string ))
488
+ } else if f .Kind () == reflect .Int64 {
489
+ f .SetInt (params [key ].(int64 ))
490
+ }
475
491
}
476
492
}
477
493
if params ["disableUser" ] != nil {
@@ -498,37 +514,6 @@ func (u *UserToUpdate) preparePayload(user *identitytoolkit.IdentitytoolkitRelyi
498
514
499
515
// End of validators
500
516
501
- // Response Types -------------------------------
502
-
503
- type getUserResponse struct {
504
- RequestType string
505
- Users []responseUserRecord
506
- }
507
-
508
- type responseUserRecord struct {
509
- UID string
510
- DisplayName string
511
- Email string
512
- PhoneNumber string
513
- PhotoURL string
514
- CreationTimestamp int64
515
- LastLogInTimestamp int64
516
- ProviderID string
517
- CustomClaims string
518
- Disabled bool
519
- EmailVerified bool
520
- ProviderUserInfo []* UserInfo
521
- PasswordHash string
522
- PasswordSalt string
523
- ValidSince int64
524
- }
525
-
526
- type listUsersResponse struct {
527
- RequestType string
528
- Users []responseUserRecord
529
- NextPage string
530
- }
531
-
532
517
// Helper functions for retrieval and HTTP calls.
533
518
534
519
func (c * Client ) createUser (ctx context.Context , user * UserToCreate ) (string , error ) {
@@ -559,7 +544,6 @@ func (c *Client) updateUser(ctx context.Context, uid string, user *UserToUpdate)
559
544
if user == nil || user .params == nil {
560
545
return fmt .Errorf ("update parameters must not be nil or empty" )
561
546
}
562
-
563
547
request := & identitytoolkit.IdentitytoolkitRelyingpartySetAccountInfoRequest {
564
548
LocalId : uid ,
565
549
}
@@ -628,10 +612,11 @@ func makeExportedUser(r *identitytoolkit.UserInfo) (*ExportedUserRecord, error)
628
612
ProviderID : defaultProviderID ,
629
613
UID : r .LocalId ,
630
614
},
631
- CustomClaims : cc ,
632
- Disabled : r .Disabled ,
633
- EmailVerified : r .EmailVerified ,
634
- ProviderUserInfo : providerUserInfo ,
615
+ CustomClaims : cc ,
616
+ Disabled : r .Disabled ,
617
+ EmailVerified : r .EmailVerified ,
618
+ ProviderUserInfo : providerUserInfo ,
619
+ TokensValidAfterMillis : r .ValidSince * 1000 ,
635
620
UserMetadata : & UserMetadata {
636
621
LastLogInTimestamp : r .LastLoginAt ,
637
622
CreationTimestamp : r .CreatedAt ,
0 commit comments