@@ -39,6 +39,8 @@ type GitHubAuthConfig struct {
39
39
TokenDB string `yaml:"token_db,omitempty"`
40
40
HTTPTimeout time.Duration `yaml:"http_timeout,omitempty"`
41
41
RevalidateAfter time.Duration `yaml:"revalidate_after,omitempty"`
42
+ GithubWebUri string `yaml:"github_web_uri,omitempty"`
43
+ GithubApiUri string `yaml:"github_api_uri,omitempty"`
42
44
}
43
45
44
46
type GitHubAuthRequest struct {
@@ -90,13 +92,30 @@ func (gha *GitHubAuth) DoGitHubAuth(rw http.ResponseWriter, req *http.Request) {
90
92
}
91
93
}
92
94
95
+ func (gha * GitHubAuth ) getGithubApiUri () string {
96
+ if gha .config .GithubApiUri != "" {
97
+ return gha .config .GithubApiUri
98
+ } else {
99
+ return "https://api.github.com"
100
+ }
101
+ }
102
+
103
+ func (gha * GitHubAuth ) getGithubWebUri () string {
104
+ if gha .config .GithubWebUri != "" {
105
+ return gha .config .GithubWebUri
106
+ } else {
107
+ return "https://github.com"
108
+ }
109
+ }
110
+
93
111
func (gha * GitHubAuth ) doGitHubAuthCreateToken (rw http.ResponseWriter , code string ) {
94
112
data := url.Values {
95
113
"code" : []string {string (code )},
96
114
"client_id" : []string {gha .config .ClientId },
97
115
"client_secret" : []string {gha .config .ClientSecret },
98
116
}
99
- req , err := http .NewRequest ("POST" , "https://github.com/login/oauth/access_token" , bytes .NewBufferString (data .Encode ()))
117
+
118
+ req , err := http .NewRequest ("POST" , fmt .Sprintf ("%s/login/oauth/access_token" , gha .getGithubWebUri ()), bytes .NewBufferString (data .Encode ()))
100
119
if err != nil {
101
120
http .Error (rw , fmt .Sprintf ("Error creating request to GitHub auth backend: %s" , err ), http .StatusServiceUnavailable )
102
121
return
@@ -150,7 +169,7 @@ func (gha *GitHubAuth) doGitHubAuthCreateToken(rw http.ResponseWriter, code stri
150
169
}
151
170
152
171
func (gha * GitHubAuth ) validateAccessToken (token string ) (user string , err error ) {
153
- req , err := http .NewRequest ("GET" , "https://api.github.com/ user" , nil )
172
+ req , err := http .NewRequest ("GET" , fmt . Sprintf ( "%s/ user", gha . getGithubApiUri ()) , nil )
154
173
if err != nil {
155
174
err = fmt .Errorf ("could not create request to get information for token %s: %s" , token , err )
156
175
return
@@ -187,7 +206,7 @@ func (gha *GitHubAuth) checkOrganization(token, user string) (err error) {
187
206
if gha .config .Organization == "" {
188
207
return nil
189
208
}
190
- url := fmt .Sprintf ("https://api.github.com/ orgs/%s/members/%s" , gha .config .Organization , user )
209
+ url := fmt .Sprintf ("%s/ orgs/%s/members/%s" , gha . getGithubApiUri () , gha .config .Organization , user )
191
210
req , err := http .NewRequest ("GET" , url , nil )
192
211
if err != nil {
193
212
err = fmt .Errorf ("could not create request to get organization membership: %s" , err )
0 commit comments