git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #269 from jehiah/github_enterprise_269
9b68e8bJehiah Czebotar
README.md+4−5
@@ -97,12 +97,11 @@ The GitHub auth provider supports two additional parameters to restrict authenti
97 -github-org="": restrict logins to members of this organisation
97 -github-org="": restrict logins to members of this organisation
98 -github-team="": restrict logins to members of any of these teams, separated by a comma
98 -github-team="": restrict logins to members of any of these teams, separated by a comma
99
99
100−If you are using github enterprise, make sure you set the following to the appropriate url:
100+If you are using GitHub enterprise, make sure you set the following to the appropriate url:
101−
102− -login-url="<enterprise github url>/login/oauth/authorize"
103− -redeem-url="<enterprise github url>/login/oauth/access_token"
104− -validate-url="<enterprise github api url>/user/emails"
105
101
102+ -login-url="http(s)://<enterprise github host>/login/oauth/authorize"
103+ -redeem-url="http(s)://<enterprise github host>/login/oauth/access_token"
104+ -validate-url="http(s)://<enterprise github host>/api/v3"
106
105
107### GitLab Auth Provider
106### GitLab Auth Provider
108
107
providers/github.go+25−7
@@ -7,6 +7,7 @@ import (
7 "log"
7 "log"
8 "net/http"
8 "net/http"
9 "net/url"
9 "net/url"
10+ "path"
10 "strings"
11 "strings"
11)
12)
12
13
@@ -32,11 +33,12 @@ func NewGitHubProvider(p *ProviderData) *GitHubProvider {
32 Path: "/login/oauth/access_token",
33 Path: "/login/oauth/access_token",
33 }
34 }
34 }
35 }
36+ // ValidationURL is the API Base URL
35 if p.ValidateURL == nil || p.ValidateURL.String() == "" {
37 if p.ValidateURL == nil || p.ValidateURL.String() == "" {
36 p.ValidateURL = &url.URL{
38 p.ValidateURL = &url.URL{
37 Scheme: "https",
39 Scheme: "https",
38 Host: "api.github.com",
40 Host: "api.github.com",
39− Path: "/user/emails",
41+ Path: "/",
40 }
42 }
41 }
43 }
42 if p.Scope == "" {
44 if p.Scope == "" {
@@ -64,8 +66,13 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
64 "limit": {"100"},
66 "limit": {"100"},
65 }
67 }
66
68
69+ endpoint := &url.URL{
67− endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + "/user/orgs?" + params.Encode()
70+ Scheme: p.ValidateURL.Scheme,
71+ Host: p.ValidateURL.Host,
72+ Path: path.Join(p.ValidateURL.Path, "/user/orgs"),
73+ RawQuery: params.Encode(),
74+ }
68− req, _ := http.NewRequest("GET", endpoint, nil)
75+ req, _ := http.NewRequest("GET", endpoint.String(), nil)
69 req.Header.Set("Accept", "application/vnd.github.v3+json")
76 req.Header.Set("Accept", "application/vnd.github.v3+json")
70 resp, err := http.DefaultClient.Do(req)
77 resp, err := http.DefaultClient.Do(req)
71 if err != nil {
78 if err != nil {
@@ -114,8 +121,13 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
114 "limit": {"100"},
121 "limit": {"100"},
115 }
122 }
116
123
124+ endpoint := &url.URL{
117− endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + "/user/teams?" + params.Encode()
125+ Scheme: p.ValidateURL.Scheme,
126+ Host: p.ValidateURL.Host,
127+ Path: path.Join(p.ValidateURL.Path, "/user/teams"),
128+ RawQuery: params.Encode(),
129+ }
118− req, _ := http.NewRequest("GET", endpoint, nil)
130+ req, _ := http.NewRequest("GET", endpoint.String(), nil)
119 req.Header.Set("Accept", "application/vnd.github.v3+json")
131 req.Header.Set("Accept", "application/vnd.github.v3+json")
120 resp, err := http.DefaultClient.Do(req)
132 resp, err := http.DefaultClient.Do(req)
121 if err != nil {
133 if err != nil {
@@ -187,8 +199,14 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
187 params := url.Values{
199 params := url.Values{
188 "access_token": {s.AccessToken},
200 "access_token": {s.AccessToken},
189 }
201 }
190− endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + p.ValidateURL.Path + "?" + params.Encode()
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+ }
191− resp, err := http.DefaultClient.Get(endpoint)
209+ resp, err := http.DefaultClient.Get(endpoint.String())
192 if err != nil {
210 if err != nil {
193 return "", err
211 return "", err
194 }
212 }