Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix yahoo user fetching #577

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading