git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #96 from caarlos0/verified

fix: github should check if email is verified

commitd3b823287636b83a3d01b40ec9e5db26dd3d5c2b authorJoel Speed <Joel.speed@hotmail.co.uk> dateThu 11 Apr 2019, 13:55 (8 years ago) parent3f4420fd00e3bd
3 files changed+21−6
CHANGELOG.md+1 providers/github.go+4−3 providers/github_test.go+16−3
CHANGELOG.md+1
@@ -2,6 +2,7 @@
22
33## Changes since v3.1.0
44
5+- [#96](https://github.com/bitly/oauth2_proxy/pull/96) Check if email is verified on GitHub (@caarlos0)
56- [#110](https://github.com/pusher/oauth2_proxy/pull/110) Added GCP healthcheck option (@timothy-spencer)
67- [#112](https://github.com/pusher/oauth2_proxy/pull/112) Improve websocket support (@gyson)
78- [#63](https://github.com/pusher/oauth2_proxy/pull/63) Use encoding/json for SessionState serialization (@yaegashi)
providers/github.go+4−3
@@ -202,8 +202,9 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
202202func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
203203
204204 var emails []struct {
205− Email string `json:"email"`
206− Primary bool `json:"primary"`
205+ Email string `json:"email"`
206+ Primary bool `json:"primary"`
207+ Verified bool `json:"verified"`
207208 }
208209
209210 // if we require an Org or Team, check that first
@@ -248,7 +249,7 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
248249 }
249250
250251 for _, email := range emails {
251− if email.Primary {
252+ if email.Primary && email.Verified {
252253 return email.Email, nil
253254 }
254255 }
providers/github_test.go+16−3
@@ -97,7 +97,7 @@ func TestGitHubProviderOverrides(t *testing.T) {
9797}
9898
9999func TestGitHubProviderGetEmailAddress(t *testing.T) {
100− b := testGitHubBackend([]string{`[ {"email": "michael.bland@gsa.gov", "primary": true} ]`})
100+ b := testGitHubBackend([]string{`[ {"email": "michael.bland@gsa.gov", "verified": true, "primary": true} ]`})
101101 defer b.Close()
102102
103103 bURL, _ := url.Parse(b.URL)
@@ -109,10 +109,23 @@ func TestGitHubProviderGetEmailAddress(t *testing.T) {
109109 assert.Equal(t, "michael.bland@gsa.gov", email)
110110}
111111
112+func TestGitHubProviderGetEmailAddressNotVerified(t *testing.T) {
113+ b := testGitHubBackend([]string{`[ {"email": "michael.bland@gsa.gov", "verified": false, "primary": true} ]`})
114+ defer b.Close()
115+
116+ bURL, _ := url.Parse(b.URL)
117+ p := testGitHubProvider(bURL.Host)
118+
119+ session := &SessionState{AccessToken: "imaginary_access_token"}
120+ email, err := p.GetEmailAddress(session)
121+ assert.Equal(t, nil, err)
122+ assert.Empty(t, "", email)
123+}
124+
112125func TestGitHubProviderGetEmailAddressWithOrg(t *testing.T) {
113126 b := testGitHubBackend([]string{
114− `[ {"email": "michael.bland@gsa.gov", "primary": true, "login":"testorg"} ]`,
115− `[ {"email": "michael.bland1@gsa.gov", "primary": true, "login":"testorg1"} ]`,
127+ `[ {"email": "michael.bland@gsa.gov", "primary": true, "verified": true, "login":"testorg"} ]`,
128+ `[ {"email": "michael.bland1@gsa.gov", "primary": true, "verified": true, "login":"testorg1"} ]`,
116129 `[ ]`,
117130 })
118131 defer b.Close()