@@ -7,6 +7,7 @@ import (
77 "log"
88 "net/http"
99 "net/url"
10+ "path"
1011 "strings"
1112)
1213
@@ -32,11 +33,12 @@ func NewGitHubProvider(p *ProviderData) *GitHubProvider {
3233 Path: "/login/oauth/access_token",
3334 }
3435 }
36+ // ValidationURL is the API Base URL
3537 if p.ValidateURL == nil || p.ValidateURL.String() == "" {
3638 p.ValidateURL = &url.URL{
3739 Scheme: "https",
3840 Host: "api.github.com",
39− Path: "/user/emails",
41+ Path: "/",
4042 }
4143 }
4244 if p.Scope == "" {
@@ -64,8 +66,13 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
6466 "limit": {"100"},
6567 }
6668
67− endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + "/user/orgs?" + params.Encode()
68− req, _ := http.NewRequest("GET", endpoint, nil)
69+ endpoint := &url.URL{
70+ Scheme: p.ValidateURL.Scheme,
71+ Host: p.ValidateURL.Host,
72+ Path: path.Join(p.ValidateURL.Path, "/user/orgs"),
73+ RawQuery: params.Encode(),
74+ }
75+ req, _ := http.NewRequest("GET", endpoint.String(), nil)
6976 req.Header.Set("Accept", "application/vnd.github.v3+json")
7077 resp, err := http.DefaultClient.Do(req)
7178 if err != nil {
@@ -114,8 +121,13 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
114121 "limit": {"100"},
115122 }
116123
117− endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + "/user/teams?" + params.Encode()
118− req, _ := http.NewRequest("GET", endpoint, nil)
124+ endpoint := &url.URL{
125+ Scheme: p.ValidateURL.Scheme,
126+ Host: p.ValidateURL.Host,
127+ Path: path.Join(p.ValidateURL.Path, "/user/teams"),
128+ RawQuery: params.Encode(),
129+ }
130+ req, _ := http.NewRequest("GET", endpoint.String(), nil)
119131 req.Header.Set("Accept", "application/vnd.github.v3+json")
120132 resp, err := http.DefaultClient.Do(req)
121133 if err != nil {
@@ -187,8 +199,14 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
187199 params := url.Values{
188200 "access_token": {s.AccessToken},
189201 }
190− endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + p.ValidateURL.Path + "?" + params.Encode()
191− resp, err := http.DefaultClient.Get(endpoint)
202+
203+ endpoint := &url.URL{
204+ Scheme: p.ValidateURL.Scheme,
205+ Host: p.ValidateURL.Host,
206+ Path: path.Join(p.ValidateURL.Path, "/user/emails"),
207+ RawQuery: params.Encode(),
208+ }
209+ resp, err := http.DefaultClient.Get(endpoint.String())
192210 if err != nil {
193211 return "", err
194212 }