Skip to content

Commit

Permalink
Merge pull request #33 from davidwarshaw/user-identity-profile-data
Browse files Browse the repository at this point in the history
Add profileData key to UserIdentity
  • Loading branch information
sergiught authored Apr 6, 2022
2 parents 7d73f02 + ceb079f commit 6eab95f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
15 changes: 8 additions & 7 deletions management/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ type UserIdentityLink struct {

// UserIdentity holds values that validate a User's identity.
type UserIdentity struct {
Connection *string `json:"connection,omitempty"`
UserID *string `json:"-"`
Provider *string `json:"provider,omitempty"`
IsSocial *bool `json:"isSocial,omitempty"`
AccessToken *string `json:"access_token,omitempty"`
AccessTokenSecret *string `json:"access_token_secret,omitempty"`
RefreshToken *string `json:"refresh_token,omitempty"`
Connection *string `json:"connection,omitempty"`
UserID *string `json:"-"`
Provider *string `json:"provider,omitempty"`
IsSocial *bool `json:"isSocial,omitempty"`
AccessToken *string `json:"access_token,omitempty"`
AccessTokenSecret *string `json:"access_token_secret,omitempty"`
RefreshToken *string `json:"refresh_token,omitempty"`
ProfileData *map[string]interface{} `json:"profileData,omitempty"`
}

// UnmarshalJSON is a custom deserializer for the UserIdentity type.
Expand Down
16 changes: 11 additions & 5 deletions management/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/auth0/go-auth0"
"github.com/auth0/go-auth0/internal/testing/expect"
)
Expand Down Expand Up @@ -387,18 +389,22 @@ func TestUserIdentity(t *testing.T) {
})

t.Run("UnmarshalJSON", func(t *testing.T) {
for b, expected := range map[string]*UserIdentity{
for expectedAsString, expected := range map[string]*UserIdentity{
`{}`: {UserID: nil},
`{"user_id":1}`: {UserID: auth0.String("1")},
`{"user_id":"1"}`: {UserID: auth0.String("1")},
`{"user_id":"foo"}`: {UserID: auth0.String("foo")},
`{"profileData": {"picture": "some-picture.jpeg"}}`: {
ProfileData: &map[string]interface{}{
"picture": "some-picture.jpeg",
},
},
} {
var u UserIdentity
err := json.Unmarshal([]byte(b), &u)
if err != nil {
var actual *UserIdentity
if err := json.Unmarshal([]byte(expectedAsString), &actual); err != nil {
t.Error(err)
}
expect.Expect(t, u.GetUserID(), expected.GetUserID())
assert.Equal(t, expected, actual)
}
})
}

0 comments on commit 6eab95f

Please sign in to comment.