Skip to content

Commit d798ec6

Browse files
authored
constant provider id plus tests (#64)
* Constant provider id plus tests * Cleaning up the json tags in the structs following the identitytoolkit PR * Expand comment about ProviderID
1 parent f4d07f6 commit d798ec6

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

auth/user_mgt.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
const maxReturnedResults = 1000
3131
const maxLenPayloadCC = 1000
3232

33+
const defaultProviderID = "firebase"
34+
3335
var commonValidators = map[string]func(interface{}) error{
3436
"displayName": validateDisplayName,
3537
"email": validateEmail,
@@ -51,14 +53,15 @@ func (c *Client) setHeader(ic identitytoolkitCall) {
5153

5254
// UserInfo is a collection of standard profile information for a user.
5355
type UserInfo struct {
54-
DisplayName string `json:"displayName,omitempty"`
55-
Email string `json:"email,omitempty"`
56-
PhoneNumber string `json:"phoneNumber,omitempty"`
57-
PhotoURL string `json:"photoUrl,omitempty"`
58-
// ProviderID can be a short domain name (e.g. google.com),
56+
DisplayName string
57+
Email string
58+
PhoneNumber string
59+
PhotoURL string
60+
// In the ProviderUserInfo[] ProviderID can be a short domain name (e.g. google.com),
5961
// or the identity of an OpenID identity provider.
60-
ProviderID string `json:"providerId,omitempty"`
61-
UID string `json:"localId,omitempty"`
62+
// In UserRecord.UserInfo it will return the constant string "firebase".
63+
ProviderID string
64+
UID string
6265
}
6366

6467
// UserMetadata contains additional metadata associated with a user account.
@@ -498,32 +501,32 @@ func (u *UserToUpdate) preparePayload(user *identitytoolkit.IdentitytoolkitRelyi
498501
// Response Types -------------------------------
499502

500503
type getUserResponse struct {
501-
RequestType string `json:"kind,omitempty"`
502-
Users []responseUserRecord `json:"users,omitempty"`
504+
RequestType string
505+
Users []responseUserRecord
503506
}
504507

505508
type responseUserRecord struct {
506-
UID string `json:"localId,omitempty"`
507-
DisplayName string `json:"displayName,omitempty"`
508-
Email string `json:"email,omitempty"`
509-
PhoneNumber string `json:"phoneNumber,omitempty"`
510-
PhotoURL string `json:"photoUrl,omitempty"`
511-
CreationTimestamp int64 `json:"createdAt,string,omitempty"`
512-
LastLogInTimestamp int64 `json:"lastLoginAt,string,omitempty"`
513-
ProviderID string `json:"providerId,omitempty"`
514-
CustomClaims string `json:"customAttributes,omitempty"`
515-
Disabled bool `json:"disabled,omitempty"`
516-
EmailVerified bool `json:"emailVerified,omitempty"`
517-
ProviderUserInfo []*UserInfo `json:"providerUserInfo,omitempty"`
518-
PasswordHash string `json:"passwordHash,omitempty"`
519-
PasswordSalt string `json:"salt,omitempty"`
520-
ValidSince int64 `json:"validSince,string,omitempty"`
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
521524
}
522525

523526
type listUsersResponse struct {
524-
RequestType string `json:"kind,omitempty"`
525-
Users []responseUserRecord `json:"users,omitempty"`
526-
NextPage string `json:"nextPageToken,omitempty"`
527+
RequestType string
528+
Users []responseUserRecord
529+
NextPage string
527530
}
528531

529532
// Helper functions for retrieval and HTTP calls.
@@ -622,6 +625,7 @@ func makeExportedUser(r *identitytoolkit.UserInfo) (*ExportedUserRecord, error)
622625
Email: r.Email,
623626
PhoneNumber: r.PhoneNumber,
624627
PhotoURL: r.PhotoUrl,
628+
ProviderID: defaultProviderID,
625629
UID: r.LocalId,
626630
},
627631
CustomClaims: cc,

auth/user_mgt_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var testUser = &UserRecord{
4141
PhoneNumber: "+1234567890",
4242
DisplayName: "Test User",
4343
PhotoURL: "http://www.example.com/testuser/photo.png",
44+
ProviderID: defaultProviderID,
4445
},
4546
Disabled: false,
4647

integration/auth/user_mgt_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ func testUpdateUser(t *testing.T) {
212212
}
213213

214214
want := &auth.UserRecord{
215-
UserInfo: &auth.UserInfo{UID: testFixtures.sampleUserBlank.UID},
215+
UserInfo: &auth.UserInfo{
216+
UID: testFixtures.sampleUserBlank.UID,
217+
ProviderID: "firebase",
218+
},
216219
UserMetadata: &auth.UserMetadata{
217220
CreationTimestamp: testFixtures.sampleUserBlank.UserMetadata.CreationTimestamp,
218221
},
@@ -241,6 +244,7 @@ func testUpdateUser(t *testing.T) {
241244
DisplayName: "name",
242245
PhoneNumber: "+12345678901",
243246
PhotoURL: "http://photo.png",
247+
ProviderID: "firebase",
244248
Email: "abc@ab.ab",
245249
},
246250
UserMetadata: &auth.UserMetadata{

0 commit comments

Comments
 (0)