From b49aeb222b820b13a8e9f5430c1201a24cf52b13 Mon Sep 17 00:00:00 2001
From: Carlos Alexandro Becker <caarlos0@gmail.com>
Date: Mon, 11 Mar 2019 14:52:08 -0300
Subject: [PATCH] fix: should check if email is verified

---
 providers/github.go      | 6 +++---
 providers/github_test.go | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/providers/github.go b/providers/github.go
index d39ee2b6..26d8c3f7 100644
--- a/providers/github.go
+++ b/providers/github.go
@@ -202,8 +202,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
@@ -248,7 +248,7 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
 	}
 
 	for _, email := range emails {
-		if email.Primary {
+		if email.Verified {
 			return email.Email, nil
 		}
 	}
diff --git a/providers/github_test.go b/providers/github_test.go
index c96877cb..2da2a329 100644
--- a/providers/github_test.go
+++ b/providers/github_test.go
@@ -97,7 +97,7 @@ func TestGitHubProviderOverrides(t *testing.T) {
 }
 
 func TestGitHubProviderGetEmailAddress(t *testing.T) {
-	b := testGitHubBackend([]string{`[ {"email": "michael.bland@gsa.gov", "primary": true} ]`})
+	b := testGitHubBackend([]string{`[ {"email": "michael.bland@gsa.gov", "verified": true} ]`})
 	defer b.Close()
 
 	bURL, _ := url.Parse(b.URL)
@@ -111,8 +111,8 @@ func TestGitHubProviderGetEmailAddress(t *testing.T) {
 
 func TestGitHubProviderGetEmailAddressWithOrg(t *testing.T) {
 	b := testGitHubBackend([]string{
-		`[ {"email": "michael.bland@gsa.gov", "primary": true, "login":"testorg"} ]`,
-		`[ {"email": "michael.bland1@gsa.gov", "primary": true, "login":"testorg1"} ]`,
+		`[ {"email": "michael.bland@gsa.gov", "verified": true, "login":"testorg"} ]`,
+		`[ {"email": "michael.bland1@gsa.gov", "verified": true, "login":"testorg1"} ]`,
 		`[ ]`,
 	})
 	defer b.Close()