@@ -18,7 +18,7 @@ import (
18
18
"github.com/bitly/oauth2_proxy/providers"
19
19
)
20
20
21
- type OauthProxy struct {
21
+ type OAuthProxy struct {
22
22
CookieSeed string
23
23
CookieName string
24
24
CookieDomain string
@@ -31,10 +31,10 @@ type OauthProxy struct {
31
31
RobotsPath string
32
32
PingPath string
33
33
SignInPath string
34
- OauthStartPath string
35
- OauthCallbackPath string
34
+ OAuthStartPath string
35
+ OAuthCallbackPath string
36
36
37
- redirectUrl * url.URL // the url to receive requests at
37
+ redirectURL * url.URL // the url to receive requests at
38
38
provider providers.Provider
39
39
ProxyPrefix string
40
40
SignInMessage string
@@ -86,9 +86,9 @@ func NewFileServer(path string, filesystemPath string) (proxy http.Handler) {
86
86
return http .StripPrefix (path , http .FileServer (http .Dir (filesystemPath )))
87
87
}
88
88
89
- func NewOauthProxy (opts * Options , validator func (string ) bool ) * OauthProxy {
89
+ func NewOAuthProxy (opts * Options , validator func (string ) bool ) * OAuthProxy {
90
90
serveMux := http .NewServeMux ()
91
- for _ , u := range opts .proxyUrls {
91
+ for _ , u := range opts .proxyURLs {
92
92
path := u .Path
93
93
switch u .Scheme {
94
94
case "http" , "https" :
@@ -116,10 +116,10 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
116
116
log .Printf ("compiled skip-auth-regex => %q" , u )
117
117
}
118
118
119
- redirectUrl := opts .redirectUrl
120
- redirectUrl .Path = fmt .Sprintf ("%s/callback" , opts .ProxyPrefix )
119
+ redirectURL := opts .redirectURL
120
+ redirectURL .Path = fmt .Sprintf ("%s/callback" , opts .ProxyPrefix )
121
121
122
- log .Printf ("OauthProxy configured for %s Client ID: %s" , opts .provider .Data ().ProviderName , opts .ClientID )
122
+ log .Printf ("OAuthProxy configured for %s Client ID: %s" , opts .provider .Data ().ProviderName , opts .ClientID )
123
123
domain := opts .CookieDomain
124
124
if domain == "" {
125
125
domain = "<default>"
@@ -141,7 +141,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
141
141
}
142
142
}
143
143
144
- return & OauthProxy {
144
+ return & OAuthProxy {
145
145
CookieName : opts .CookieName ,
146
146
CookieSeed : opts .CookieSecret ,
147
147
CookieDomain : opts .CookieDomain ,
@@ -154,13 +154,13 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
154
154
RobotsPath : "/robots.txt" ,
155
155
PingPath : "/ping" ,
156
156
SignInPath : fmt .Sprintf ("%s/sign_in" , opts .ProxyPrefix ),
157
- OauthStartPath : fmt .Sprintf ("%s/start" , opts .ProxyPrefix ),
158
- OauthCallbackPath : fmt .Sprintf ("%s/callback" , opts .ProxyPrefix ),
157
+ OAuthStartPath : fmt .Sprintf ("%s/start" , opts .ProxyPrefix ),
158
+ OAuthCallbackPath : fmt .Sprintf ("%s/callback" , opts .ProxyPrefix ),
159
159
160
160
ProxyPrefix : opts .ProxyPrefix ,
161
161
provider : opts .provider ,
162
162
serveMux : serveMux ,
163
- redirectUrl : redirectUrl ,
163
+ redirectURL : redirectURL ,
164
164
skipAuthRegex : opts .SkipAuthRegex ,
165
165
compiledRegex : opts .CompiledRegex ,
166
166
PassBasicAuth : opts .PassBasicAuth ,
@@ -171,13 +171,13 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
171
171
}
172
172
}
173
173
174
- func (p * OauthProxy ) GetRedirectURI (host string ) string {
174
+ func (p * OAuthProxy ) GetRedirectURI (host string ) string {
175
175
// default to the request Host if not set
176
- if p .redirectUrl .Host != "" {
177
- return p .redirectUrl .String ()
176
+ if p .redirectURL .Host != "" {
177
+ return p .redirectURL .String ()
178
178
}
179
179
var u url.URL
180
- u = * p .redirectUrl
180
+ u = * p .redirectURL
181
181
if u .Scheme == "" {
182
182
if p .CookieSecure {
183
183
u .Scheme = "https"
@@ -189,16 +189,16 @@ func (p *OauthProxy) GetRedirectURI(host string) string {
189
189
return u .String ()
190
190
}
191
191
192
- func (p * OauthProxy ) displayCustomLoginForm () bool {
192
+ func (p * OAuthProxy ) displayCustomLoginForm () bool {
193
193
return p .HtpasswdFile != nil && p .DisplayHtpasswdForm
194
194
}
195
195
196
- func (p * OauthProxy ) redeemCode (host , code string ) (s * providers.SessionState , err error ) {
196
+ func (p * OAuthProxy ) redeemCode (host , code string ) (s * providers.SessionState , err error ) {
197
197
if code == "" {
198
198
return nil , errors .New ("missing code" )
199
199
}
200
- redirectUri := p .GetRedirectURI (host )
201
- s , err = p .provider .Redeem (redirectUri , code )
200
+ redirectURI := p .GetRedirectURI (host )
201
+ s , err = p .provider .Redeem (redirectURI , code )
202
202
if err != nil {
203
203
return
204
204
}
@@ -209,7 +209,7 @@ func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, e
209
209
return
210
210
}
211
211
212
- func (p * OauthProxy ) MakeCookie (req * http.Request , value string , expiration time.Duration , now time.Time ) * http.Cookie {
212
+ func (p * OAuthProxy ) MakeCookie (req * http.Request , value string , expiration time.Duration , now time.Time ) * http.Cookie {
213
213
domain := req .Host
214
214
if h , _ , err := net .SplitHostPort (domain ); err == nil {
215
215
domain = h
@@ -235,15 +235,15 @@ func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time
235
235
}
236
236
}
237
237
238
- func (p * OauthProxy ) ClearCookie (rw http.ResponseWriter , req * http.Request ) {
238
+ func (p * OAuthProxy ) ClearCookie (rw http.ResponseWriter , req * http.Request ) {
239
239
http .SetCookie (rw , p .MakeCookie (req , "" , time .Hour * - 1 , time .Now ()))
240
240
}
241
241
242
- func (p * OauthProxy ) SetCookie (rw http.ResponseWriter , req * http.Request , val string ) {
242
+ func (p * OAuthProxy ) SetCookie (rw http.ResponseWriter , req * http.Request , val string ) {
243
243
http .SetCookie (rw , p .MakeCookie (req , val , p .CookieExpire , time .Now ()))
244
244
}
245
245
246
- func (p * OauthProxy ) LoadCookiedSession (req * http.Request ) (* providers.SessionState , time.Duration , error ) {
246
+ func (p * OAuthProxy ) LoadCookiedSession (req * http.Request ) (* providers.SessionState , time.Duration , error ) {
247
247
var age time.Duration
248
248
c , err := req .Cookie (p .CookieName )
249
249
if err != nil {
@@ -264,7 +264,7 @@ func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionSt
264
264
return session , age , nil
265
265
}
266
266
267
- func (p * OauthProxy ) SaveSession (rw http.ResponseWriter , req * http.Request , s * providers.SessionState ) error {
267
+ func (p * OAuthProxy ) SaveSession (rw http.ResponseWriter , req * http.Request , s * providers.SessionState ) error {
268
268
value , err := p .provider .CookieForSession (s , p .CookieCipher )
269
269
if err != nil {
270
270
return err
@@ -273,17 +273,17 @@ func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *p
273
273
return nil
274
274
}
275
275
276
- func (p * OauthProxy ) RobotsTxt (rw http.ResponseWriter ) {
276
+ func (p * OAuthProxy ) RobotsTxt (rw http.ResponseWriter ) {
277
277
rw .WriteHeader (http .StatusOK )
278
278
fmt .Fprintf (rw , "User-agent: *\n Disallow: /" )
279
279
}
280
280
281
- func (p * OauthProxy ) PingPage (rw http.ResponseWriter ) {
281
+ func (p * OAuthProxy ) PingPage (rw http.ResponseWriter ) {
282
282
rw .WriteHeader (http .StatusOK )
283
283
fmt .Fprintf (rw , "OK" )
284
284
}
285
285
286
- func (p * OauthProxy ) ErrorPage (rw http.ResponseWriter , code int , title string , message string ) {
286
+ func (p * OAuthProxy ) ErrorPage (rw http.ResponseWriter , code int , title string , message string ) {
287
287
log .Printf ("ErrorPage %d %s %s" , code , title , message )
288
288
rw .WriteHeader (code )
289
289
t := struct {
@@ -298,7 +298,7 @@ func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
298
298
p .templates .ExecuteTemplate (rw , "error.html" , t )
299
299
}
300
300
301
- func (p * OauthProxy ) SignInPage (rw http.ResponseWriter , req * http.Request , code int ) {
301
+ func (p * OAuthProxy ) SignInPage (rw http.ResponseWriter , req * http.Request , code int ) {
302
302
p .ClearCookie (rw , req )
303
303
rw .WriteHeader (code )
304
304
@@ -325,7 +325,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
325
325
p .templates .ExecuteTemplate (rw , "sign_in.html" , t )
326
326
}
327
327
328
- func (p * OauthProxy ) ManualSignIn (rw http.ResponseWriter , req * http.Request ) (string , bool ) {
328
+ func (p * OAuthProxy ) ManualSignIn (rw http.ResponseWriter , req * http.Request ) (string , bool ) {
329
329
if req .Method != "POST" || p .HtpasswdFile == nil {
330
330
return "" , false
331
331
}
@@ -342,7 +342,7 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
342
342
return "" , false
343
343
}
344
344
345
- func (p * OauthProxy ) GetRedirect (req * http.Request ) (string , error ) {
345
+ func (p * OAuthProxy ) GetRedirect (req * http.Request ) (string , error ) {
346
346
err := req .ParseForm ()
347
347
348
348
if err != nil {
@@ -358,7 +358,7 @@ func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
358
358
return redirect , err
359
359
}
360
360
361
- func (p * OauthProxy ) IsWhitelistedPath (path string ) (ok bool ) {
361
+ func (p * OAuthProxy ) IsWhitelistedPath (path string ) (ok bool ) {
362
362
for _ , u := range p .compiledRegex {
363
363
ok = u .MatchString (path )
364
364
if ok {
@@ -376,7 +376,7 @@ func getRemoteAddr(req *http.Request) (s string) {
376
376
return
377
377
}
378
378
379
- func (p * OauthProxy ) ServeHTTP (rw http.ResponseWriter , req * http.Request ) {
379
+ func (p * OAuthProxy ) ServeHTTP (rw http.ResponseWriter , req * http.Request ) {
380
380
switch path := req .URL .Path ; {
381
381
case path == p .RobotsPath :
382
382
p .RobotsTxt (rw )
@@ -386,16 +386,16 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
386
386
p .serveMux .ServeHTTP (rw , req )
387
387
case path == p .SignInPath :
388
388
p .SignIn (rw , req )
389
- case path == p .OauthStartPath :
390
- p .OauthStart (rw , req )
391
- case path == p .OauthCallbackPath :
392
- p .OauthCallback (rw , req )
389
+ case path == p .OAuthStartPath :
390
+ p .OAuthStart (rw , req )
391
+ case path == p .OAuthCallbackPath :
392
+ p .OAuthCallback (rw , req )
393
393
default :
394
394
p .Proxy (rw , req )
395
395
}
396
396
}
397
397
398
- func (p * OauthProxy ) SignIn (rw http.ResponseWriter , req * http.Request ) {
398
+ func (p * OAuthProxy ) SignIn (rw http.ResponseWriter , req * http.Request ) {
399
399
redirect , err := p .GetRedirect (req )
400
400
if err != nil {
401
401
p .ErrorPage (rw , 500 , "Internal Error" , err .Error ())
@@ -412,7 +412,7 @@ func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
412
412
}
413
413
}
414
414
415
- func (p * OauthProxy ) OauthStart (rw http.ResponseWriter , req * http.Request ) {
415
+ func (p * OAuthProxy ) OAuthStart (rw http.ResponseWriter , req * http.Request ) {
416
416
redirect , err := p .GetRedirect (req )
417
417
if err != nil {
418
418
p .ErrorPage (rw , 500 , "Internal Error" , err .Error ())
@@ -422,7 +422,7 @@ func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
422
422
http .Redirect (rw , req , p .provider .GetLoginURL (redirectURI , redirect ), 302 )
423
423
}
424
424
425
- func (p * OauthProxy ) OauthCallback (rw http.ResponseWriter , req * http.Request ) {
425
+ func (p * OAuthProxy ) OAuthCallback (rw http.ResponseWriter , req * http.Request ) {
426
426
remoteAddr := getRemoteAddr (req )
427
427
428
428
// finish the oauth cycle
@@ -465,7 +465,7 @@ func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
465
465
}
466
466
}
467
467
468
- func (p * OauthProxy ) Proxy (rw http.ResponseWriter , req * http.Request ) {
468
+ func (p * OAuthProxy ) Proxy (rw http.ResponseWriter , req * http.Request ) {
469
469
var saveSession , clearSession , revalidated bool
470
470
remoteAddr := getRemoteAddr (req )
471
471
@@ -555,7 +555,7 @@ func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
555
555
p .serveMux .ServeHTTP (rw , req )
556
556
}
557
557
558
- func (p * OauthProxy ) CheckBasicAuth (req * http.Request ) (* providers.SessionState , error ) {
558
+ func (p * OAuthProxy ) CheckBasicAuth (req * http.Request ) (* providers.SessionState , error ) {
559
559
if p .HtpasswdFile == nil {
560
560
return nil , nil
561
561
}
0 commit comments