Skip to content

Commit

Permalink
Add support for first and lastname for facebook and google plus
Browse files Browse the repository at this point in the history
  • Loading branch information
felixLam committed Jun 24, 2016
1 parent 4cf2710 commit b873896
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 150,7 @@ var indexTemplate = `{{range $key,$value:=.Providers}}
{{end}}`

var userTemplate = `
<p>Name: {{.Name}}</p>
<p>Name: {{.Name}} [{{.LastName}}, {{.FirstName}}]</p>
<p>Email: {{.Email}}</p>
<p>NickName: {{.NickName}}</p>
<p>Location: {{.Location}}</p>
Expand Down
16 changes: 10 additions & 6 deletions providers/facebook/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 92,14 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {

func userFromReader(reader io.Reader, user *goth.User) error {
u := struct {
ID string `json:"id"`
Email string `json:"email"`
Bio string `json:"bio"`
Name string `json:"name"`
Link string `json:"link"`
Picture struct {
ID string `json:"id"`
Email string `json:"email"`
Bio string `json:"bio"`
Name string `json:"name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Link string `json:"link"`
Picture struct {
Data struct {
URL string `json:"url"`
} `json:"data"`
Expand All @@ -113,6 115,8 @@ func userFromReader(reader io.Reader, user *goth.User) error {
}

user.Name = u.Name
user.FirstName = u.FirstName
user.LastName = u.LastName
user.NickName = u.Name
user.Email = u.Email
user.Description = u.Bio
Expand Down
14 changes: 9 additions & 5 deletions providers/gplus/gplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 99,13 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {

func userFromReader(reader io.Reader, user *goth.User) error {
u := struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
Link string `json:"link"`
Picture string `json:"picture"`
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
FirstName string `json:"given_name"`
LastName string `json:"family_name"`
Link string `json:"link"`
Picture string `json:"picture"`
}{}

err := json.NewDecoder(reader).Decode(&u)
Expand All @@ -112,6 114,8 @@ func userFromReader(reader io.Reader, user *goth.User) error {
}

user.Name = u.Name
user.FirstName = u.FirstName
user.LastName = u.LastName
user.NickName = u.Name
user.Email = u.Email
//user.Description = u.Bio
Expand Down
2 changes: 2 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,8 @@ type User struct {
Provider string
Email string
Name string
FirstName string
LastName string
NickName string
Description string
UserID string
Expand Down

0 comments on commit b873896

Please sign in to comment.