Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/markbates/goth
module github.com/nik0811/goth

go 1.15

Expand Down
37 changes: 29 additions & 8 deletions providers/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ const (
endpointEmail string = "https://api.bitbucket.org/2.0/user/emails"
)

type EmailAddress struct {
Type string `json:"type"`
Links Links `json:"links"`
Email string `json:"email"`
IsPrimary bool `json:"is_primary"`
IsConfirmed bool `json:"is_confirmed"`
}

type Links struct {
Self Self `json:"self"`
}

type Self struct {
Href string `json:"href"`
}

type MailList struct {
Values []EmailAddress `json:"values"`
Pagelen int `json:"pagelen"`
Size int `json:"size"`
Page int `json:"page"`
}

// New creates a new Bitbucket provider, and sets up important connection details.
// You should always call `bitbucket.New` to get a new Provider. Never try to create
// one manually.
Expand Down Expand Up @@ -162,21 +185,19 @@ func (p *Provider) getEmail(user *goth.User, sess *Session) error {
return fmt.Errorf("%s responded with a %d trying to fetch email addresses", p.providerName, response.StatusCode)
}

var mailList []struct {
Email string `json:"email"`
Primary bool `json:"is_primary"`
Confirmed bool `json:"is_confirmed"`
}
var mailList MailList
err = json.NewDecoder(response.Body).Decode(&mailList)
if err != nil {
return err
}
for _, v := range mailList {
if v.Primary && v.Confirmed {
user.Email = v.Email

for _, emailAddress := range mailList.Values {
if emailAddress.IsPrimary && emailAddress.IsConfirmed {
user.Email = emailAddress.Email
return nil
}
}

return fmt.Errorf("%s did not return any confirmed, primary email address", p.providerName)
}

Expand Down