loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit 3915364b9cdc64c7d764c466a7e9df507f5cbd8b
parent b759a6a898f1fb50c613bf0879d5ab7a2bad6e6f
Author: Gregor Weckbecker <gregor.weckbecker@snabble.io>
Date:   Thu, 12 Mar 2020 17:48:26 +0100

Merge pull request #166 from jackodsteel/fix-165-deprecated-auth-param

Fix #165 by using Authorization header instead
Diffstat:
Moauth2/github.go | 6++++--
Moauth2/github_test.go | 2+-
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/oauth2/github.go b/oauth2/github.go @@ -30,8 +30,10 @@ var providerGithub = Provider{ TokenURL: "https://github.com/login/oauth/access_token", GetUserInfo: func(token TokenInfo) (model.UserInfo, string, error) { gu := GithubUser{} - url := fmt.Sprintf("%v/user?access_token=%v", githubAPI, token.AccessToken) - resp, err := http.Get(url) + url := githubAPI + "/user" + req, _ := http.NewRequest("GET", url, nil) + req.Header.Set("Authorization", "token " + token.AccessToken) + resp, err := http.DefaultClient.Do(req) if err != nil { return model.UserInfo{}, "", err } diff --git a/oauth2/github_test.go b/oauth2/github_test.go @@ -42,7 +42,7 @@ var githubTestUserResponse = `{ func Test_Github_getUserInfo(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - Equal(t, "secret", r.FormValue("access_token")) + Equal(t, "token secret", r.Header.Get("Authorization")) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Write([]byte(githubTestUserResponse)) }))