Skip to content

Commit 70ca104

Browse files
committed
Fix yahoo user fetching
Prior to this commit, the Yahoo provider was using an old, discontinued endpoint. This changes it to the new, working endpoint to fetch user data. Update yahoo example
1 parent 5d0f51e commit 70ca104

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

examples/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ func main() {
113113
eveonline.New(os.Getenv("EVEONLINE_KEY"), os.Getenv("EVEONLINE_SECRET"), "http://localhost:3000/auth/eveonline/callback"),
114114
kakao.New(os.Getenv("KAKAO_KEY"), os.Getenv("KAKAO_SECRET"), "http://localhost:3000/auth/kakao/callback"),
115115

116-
// Pointed localhost.com to http://localhost:3000/auth/yahoo/callback through proxy as yahoo
117-
// does not allow to put custom ports in redirection uri
118-
yahoo.New(os.Getenv("YAHOO_KEY"), os.Getenv("YAHOO_SECRET"), "http://localhost.com"),
116+
// Pointed https://localhost.com to http://localhost:3000/auth/yahoo/callback
117+
// Yahoo only accepts urls that starts with https
118+
yahoo.New(os.Getenv("YAHOO_KEY"), os.Getenv("YAHOO_SECRET"), "https://localhost.com"),
119119
typetalk.New(os.Getenv("TYPETALK_KEY"), os.Getenv("TYPETALK_SECRET"), "http://localhost:3000/auth/typetalk/callback", "my"),
120120
slack.New(os.Getenv("SLACK_KEY"), os.Getenv("SLACK_SECRET"), "http://localhost:3000/auth/slack/callback"),
121121
stripe.New(os.Getenv("STRIPE_KEY"), os.Getenv("STRIPE_SECRET"), "http://localhost:3000/auth/stripe/callback"),

providers/yahoo/yahoo.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
const (
1616
authURL string = "https://api.login.yahoo.com/oauth2/request_auth"
1717
tokenURL string = "https://api.login.yahoo.com/oauth2/get_token"
18-
endpointProfile string = "https://social.yahooapis.com/v1/user/GUID/profile?format=json"
18+
endpointProfile string = "https://api.login.yahoo.com/openid/v1/userinfo"
1919
)
2020

2121
// Provider is the implementation of `goth.Provider` for accessing Yahoo.
@@ -123,27 +123,29 @@ func newConfig(provider *Provider, scopes []string) *oauth2.Config {
123123
return c
124124
}
125125

126+
type yahooUser struct {
127+
Email string `json:"email"`
128+
Name string `json:"name"`
129+
GivenName string `json:"given_name"`
130+
FamilyName string `json:"family_name"`
131+
Nickname string `json:"nickname"`
132+
Picture string `json:"picture"`
133+
Sub string `json:"sub"`
134+
}
135+
126136
func userFromReader(r io.Reader, user *goth.User) error {
127-
u := struct {
128-
Profile struct {
129-
NickName string `json:"nickname"`
130-
Location string `json:"location"`
131-
ID string `json:"guid"`
132-
Image struct {
133-
ImageURL string `json:"imageURL"`
134-
} `json:"image"`
135-
} `json:"profile"`
136-
}{}
137+
u := yahooUser{}
137138
err := json.NewDecoder(r).Decode(&u)
138139
if err != nil {
139140
return err
140141
}
141-
user.Email = "" // email is not provided by yahoo
142-
user.Name = u.Profile.NickName
143-
user.NickName = u.Profile.NickName
144-
user.UserID = u.Profile.ID
145-
user.Location = u.Profile.Location
146-
user.AvatarURL = u.Profile.Image.ImageURL
142+
user.Email = u.Email
143+
user.Name = u.Name
144+
user.FirstName = u.GivenName
145+
user.LastName = u.FamilyName
146+
user.NickName = u.Nickname
147+
user.AvatarURL = u.Picture
148+
user.UserID = u.Sub
147149
return nil
148150
}
149151

0 commit comments

Comments
 (0)