From cbc28e456b52b2140adcafbb60db558bcb110798 Mon Sep 17 00:00:00 2001 From: KS Chan Date: Wed, 5 Feb 2020 15:19:30 +0800 Subject: [PATCH] github: Use Authorization header for authentication See deprecation notice - https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters --- providers/github/github.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/providers/github/github.go b/providers/github/github.go index b3c29b967..e635f5272 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -10,7 +10,6 @@ import ( "io" "io/ioutil" "net/http" - "net/url" "strconv" "strings" @@ -105,7 +104,9 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) { return user, fmt.Errorf("%s cannot get user information without accessToken", p.providerName) } - response, err := p.Client().Get(p.profileURL + "?access_token=" + url.QueryEscape(sess.AccessToken)) + req, err := http.NewRequest("GET", p.profileURL, nil) + req.Header.Add("Authorization", "Bearer "+sess.AccessToken) + response, err := p.Client().Do(req) if err != nil { return user, err } @@ -172,7 +173,9 @@ func userFromReader(reader io.Reader, user *goth.User) error { } func getPrivateMail(p *Provider, sess *Session) (email string, err error) { - response, err := p.Client().Get(p.emailURL + "?access_token=" + url.QueryEscape(sess.AccessToken)) + req, err := http.NewRequest("GET", p.emailURL, nil) + req.Header.Add("Authorization", "Bearer "+sess.AccessToken) + response, err := p.Client().Do(req) if err != nil { if response != nil { response.Body.Close()