Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

github: check if email is verified #607

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 providers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {

var emails []struct {
Email string `json:"email"`
Primary bool `json:"primary"`
Email string `json:"email"`
Verified bool `json:"verified"`
}

// if we require an Org or Team, check that first
Expand Down Expand Up @@ -243,7 +243,7 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
}

for _, email := range emails {
if email.Primary {
if email.Verified {
return email.Email, nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions providers/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestGitHubProviderOverrides(t *testing.T) {
}

func TestGitHubProviderGetEmailAddress(t *testing.T) {
b := testGitHubBackend([]string{`[ {"email": "[email protected]", "primary": true} ]`})
b := testGitHubBackend([]string{`[ {"email": "[email protected]", "verified": true} ]`})
defer b.Close()

bURL, _ := url.Parse(b.URL)
Expand All @@ -112,8 +112,8 @@ func TestGitHubProviderGetEmailAddress(t *testing.T) {

func TestGitHubProviderGetEmailAddressWithOrg(t *testing.T) {
b := testGitHubBackend([]string{
`[ {"email": "[email protected]", "primary": true, "login":"testorg"} ]`,
`[ {"email": "[email protected]", "primary": true, "login":"testorg1"} ]`,
`[ {"email": "[email protected]", "verified": true, "login":"testorg"} ]`,
`[ {"email": "[email protected]", "verified": true, "login":"testorg1"} ]`,
`[ ]`,
})
defer b.Close()
Expand Down