Skip to content

Commit

Permalink
Fix yahoo user fetching (#577)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
narasaka authored Aug 24, 2024
1 parent 5d0f51e commit dcd8377
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func main() {
eveonline.New(os.Getenv("EVEONLINE_KEY"), os.Getenv("EVEONLINE_SECRET"), "http://localhost:3000/auth/eveonline/callback"),
kakao.New(os.Getenv("KAKAO_KEY"), os.Getenv("KAKAO_SECRET"), "http://localhost:3000/auth/kakao/callback"),

// Pointed localhost.com to http://localhost:3000/auth/yahoo/callback through proxy as yahoo
// does not allow to put custom ports in redirection uri
yahoo.New(os.Getenv("YAHOO_KEY"), os.Getenv("YAHOO_SECRET"), "http://localhost.com"),
// Pointed https://localhost.com to http://localhost:3000/auth/yahoo/callback
// Yahoo only accepts urls that starts with https
yahoo.New(os.Getenv("YAHOO_KEY"), os.Getenv("YAHOO_SECRET"), "https://localhost.com"),
typetalk.New(os.Getenv("TYPETALK_KEY"), os.Getenv("TYPETALK_SECRET"), "http://localhost:3000/auth/typetalk/callback", "my"),
slack.New(os.Getenv("SLACK_KEY"), os.Getenv("SLACK_SECRET"), "http://localhost:3000/auth/slack/callback"),
stripe.New(os.Getenv("STRIPE_KEY"), os.Getenv("STRIPE_SECRET"), "http://localhost:3000/auth/stripe/callback"),
Expand Down
36 changes: 19 additions & 17 deletions providers/yahoo/yahoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
authURL string = "https://api.login.yahoo.com/oauth2/request_auth"
tokenURL string = "https://api.login.yahoo.com/oauth2/get_token"
endpointProfile string = "https://social.yahooapis.com/v1/user/GUID/profile?format=json"
endpointProfile string = "https://api.login.yahoo.com/openid/v1/userinfo"
)

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

type yahooUser struct {
Email string `json:"email"`
Name string `json:"name"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Nickname string `json:"nickname"`
Picture string `json:"picture"`
Sub string `json:"sub"`
}

func userFromReader(r io.Reader, user *goth.User) error {
u := struct {
Profile struct {
NickName string `json:"nickname"`
Location string `json:"location"`
ID string `json:"guid"`
Image struct {
ImageURL string `json:"imageURL"`
} `json:"image"`
} `json:"profile"`
}{}
u := yahooUser{}
err := json.NewDecoder(r).Decode(&u)
if err != nil {
return err
}
user.Email = "" // email is not provided by yahoo
user.Name = u.Profile.NickName
user.NickName = u.Profile.NickName
user.UserID = u.Profile.ID
user.Location = u.Profile.Location
user.AvatarURL = u.Profile.Image.ImageURL
user.Email = u.Email
user.Name = u.Name
user.FirstName = u.GivenName
user.LastName = u.FamilyName
user.NickName = u.Nickname
user.AvatarURL = u.Picture
user.UserID = u.Sub
return nil
}

Expand Down

0 comments on commit dcd8377

Please sign in to comment.