Skip to content

Commit

Permalink
constant provider id plus tests (#64)
Browse files Browse the repository at this point in the history
* Constant provider id plus tests

* Cleaning up the json tags in the structs following the identitytoolkit PR

* Expand comment about ProviderID
  • Loading branch information
avishalom authored Jan 9, 2018
1 parent f4d07f6 commit d798ec6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
58 changes: 31 additions & 27 deletions auth/user_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
const maxReturnedResults = 1000
const maxLenPayloadCC = 1000

const defaultProviderID = "firebase"

var commonValidators = map[string]func(interface{}) error{
"displayName": validateDisplayName,
"email": validateEmail,
Expand All @@ -51,14 +53,15 @@ func (c *Client) setHeader(ic identitytoolkitCall) {

// UserInfo is a collection of standard profile information for a user.
type UserInfo struct {
DisplayName string `json:"displayName,omitempty"`
Email string `json:"email,omitempty"`
PhoneNumber string `json:"phoneNumber,omitempty"`
PhotoURL string `json:"photoUrl,omitempty"`
// ProviderID can be a short domain name (e.g. google.com),
DisplayName string
Email string
PhoneNumber string
PhotoURL string
// In the ProviderUserInfo[] ProviderID can be a short domain name (e.g. google.com),
// or the identity of an OpenID identity provider.
ProviderID string `json:"providerId,omitempty"`
UID string `json:"localId,omitempty"`
// In UserRecord.UserInfo it will return the constant string "firebase".
ProviderID string
UID string
}

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

type getUserResponse struct {
RequestType string `json:"kind,omitempty"`
Users []responseUserRecord `json:"users,omitempty"`
RequestType string
Users []responseUserRecord
}

type responseUserRecord struct {
UID string `json:"localId,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Email string `json:"email,omitempty"`
PhoneNumber string `json:"phoneNumber,omitempty"`
PhotoURL string `json:"photoUrl,omitempty"`
CreationTimestamp int64 `json:"createdAt,string,omitempty"`
LastLogInTimestamp int64 `json:"lastLoginAt,string,omitempty"`
ProviderID string `json:"providerId,omitempty"`
CustomClaims string `json:"customAttributes,omitempty"`
Disabled bool `json:"disabled,omitempty"`
EmailVerified bool `json:"emailVerified,omitempty"`
ProviderUserInfo []*UserInfo `json:"providerUserInfo,omitempty"`
PasswordHash string `json:"passwordHash,omitempty"`
PasswordSalt string `json:"salt,omitempty"`
ValidSince int64 `json:"validSince,string,omitempty"`
UID string
DisplayName string
Email string
PhoneNumber string
PhotoURL string
CreationTimestamp int64
LastLogInTimestamp int64
ProviderID string
CustomClaims string
Disabled bool
EmailVerified bool
ProviderUserInfo []*UserInfo
PasswordHash string
PasswordSalt string
ValidSince int64
}

type listUsersResponse struct {
RequestType string `json:"kind,omitempty"`
Users []responseUserRecord `json:"users,omitempty"`
NextPage string `json:"nextPageToken,omitempty"`
RequestType string
Users []responseUserRecord
NextPage string
}

// Helper functions for retrieval and HTTP calls.
Expand Down Expand Up @@ -622,6 +625,7 @@ func makeExportedUser(r *identitytoolkit.UserInfo) (*ExportedUserRecord, error)
Email: r.Email,
PhoneNumber: r.PhoneNumber,
PhotoURL: r.PhotoUrl,
ProviderID: defaultProviderID,
UID: r.LocalId,
},
CustomClaims: cc,
Expand Down
1 change: 1 addition & 0 deletions auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var testUser = &UserRecord{
PhoneNumber: "+1234567890",
DisplayName: "Test User",
PhotoURL: "http://www.example.com/testuser/photo.png",
ProviderID: defaultProviderID,
},
Disabled: false,

Expand Down
6 changes: 5 additions & 1 deletion integration/auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ func testUpdateUser(t *testing.T) {
}

want := &auth.UserRecord{
UserInfo: &auth.UserInfo{UID: testFixtures.sampleUserBlank.UID},
UserInfo: &auth.UserInfo{
UID: testFixtures.sampleUserBlank.UID,
ProviderID: "firebase",
},
UserMetadata: &auth.UserMetadata{
CreationTimestamp: testFixtures.sampleUserBlank.UserMetadata.CreationTimestamp,
},
Expand Down Expand Up @@ -241,6 +244,7 @@ func testUpdateUser(t *testing.T) {
DisplayName: "name",
PhoneNumber: "+12345678901",
PhotoURL: "http://photo.png",
ProviderID: "firebase",
Email: "abc@ab.ab",
},
UserMetadata: &auth.UserMetadata{
Expand Down

0 comments on commit d798ec6

Please sign in to comment.