Skip to content

Commit 6d6cb7e

Browse files
authored
Merge pull request bitly#392 from arnottcr/master
[github provider] use Authorization header, not access_token query parameter
2 parents f4c3566 + 17b1fa3 commit 6d6cb7e

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

providers/github.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
6262
}
6363

6464
params := url.Values{
65-
"access_token": {accessToken},
66-
"limit": {"100"},
65+
"limit": {"100"},
6766
}
6867

6968
endpoint := &url.URL{
@@ -74,6 +73,7 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
7473
}
7574
req, _ := http.NewRequest("GET", endpoint.String(), nil)
7675
req.Header.Set("Accept", "application/vnd.github.v3+json")
76+
req.Header.Set("Authorization", fmt.Sprintf("token %s", accessToken))
7777
resp, err := http.DefaultClient.Do(req)
7878
if err != nil {
7979
return false, err
@@ -86,7 +86,7 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
8686
}
8787
if resp.StatusCode != 200 {
8888
return false, fmt.Errorf(
89-
"got %d from %q %s", resp.StatusCode, stripToken(endpoint.String()), body)
89+
"got %d from %q %s", resp.StatusCode, endpoint.String(), body)
9090
}
9191

9292
if err := json.Unmarshal(body, &orgs); err != nil {
@@ -118,8 +118,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
118118
}
119119

120120
params := url.Values{
121-
"access_token": {accessToken},
122-
"limit": {"100"},
121+
"limit": {"100"},
123122
}
124123

125124
endpoint := &url.URL{
@@ -130,6 +129,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
130129
}
131130
req, _ := http.NewRequest("GET", endpoint.String(), nil)
132131
req.Header.Set("Accept", "application/vnd.github.v3+json")
132+
req.Header.Set("Authorization", fmt.Sprintf("token %s", accessToken))
133133
resp, err := http.DefaultClient.Do(req)
134134
if err != nil {
135135
return false, err
@@ -142,7 +142,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
142142
}
143143
if resp.StatusCode != 200 {
144144
return false, fmt.Errorf(
145-
"got %d from %q %s", resp.StatusCode, stripToken(endpoint.String()), body)
145+
"got %d from %q %s", resp.StatusCode, endpoint.String(), body)
146146
}
147147

148148
if err := json.Unmarshal(body, &teams); err != nil {
@@ -198,17 +198,14 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
198198
}
199199
}
200200

201-
params := url.Values{
202-
"access_token": {s.AccessToken},
203-
}
204-
205201
endpoint := &url.URL{
206-
Scheme: p.ValidateURL.Scheme,
207-
Host: p.ValidateURL.Host,
208-
Path: path.Join(p.ValidateURL.Path, "/user/emails"),
209-
RawQuery: params.Encode(),
202+
Scheme: p.ValidateURL.Scheme,
203+
Host: p.ValidateURL.Host,
204+
Path: path.Join(p.ValidateURL.Path, "/user/emails"),
210205
}
211-
resp, err := http.DefaultClient.Get(endpoint.String())
206+
req, _ := http.NewRequest("GET", endpoint.String(), nil)
207+
req.Header.Set("Authorization", fmt.Sprintf("token %s", s.AccessToken))
208+
resp, err := http.DefaultClient.Do(req)
212209
if err != nil {
213210
return "", err
214211
}
@@ -220,9 +217,9 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
220217

221218
if resp.StatusCode != 200 {
222219
return "", fmt.Errorf("got %d from %q %s",
223-
resp.StatusCode, stripToken(endpoint.String()), body)
220+
resp.StatusCode, endpoint.String(), body)
224221
} else {
225-
log.Printf("got %d from %q %s", resp.StatusCode, stripToken(endpoint.String()), body)
222+
log.Printf("got %d from %q %s", resp.StatusCode, endpoint.String(), body)
226223
}
227224

228225
if err := json.Unmarshal(body, &emails); err != nil {

0 commit comments

Comments
 (0)