git.iko.soy/typeable/oauth2-proxy
on master help sign in
*: rename Oauth to OAuth

Be consistent with Go capitalization styling and use a single way of spelling this across the tree.

commit6db18804f369ca1eef61667da02b22624f2ed1de authorBrandon Philips <brandon.philips@coreos.com> dateMon 9 Nov 2015, 00:57 (11 years ago) parent1ff2fce
3 files changed+44−44
main.go+3−3 oauthproxy.go+33−33 oauthproxy_test.go+8−8
main.go+3−3
@@ -66,8 +66,8 @@ func main() {
6666 flagSet.String("redeem-url", "", "Token redemption endpoint")
6767 flagSet.String("profile-url", "", "Profile access endpoint")
6868 flagSet.String("validate-url", "", "Access token validation endpoint")
69− flagSet.String("scope", "", "Oauth scope specification")
70− flagSet.String("approval-prompt", "force", "Oauth approval_prompt")
69+ flagSet.String("scope", "", "OAuth scope specification")
70+ flagSet.String("approval-prompt", "force", "OAuth approval_prompt")
7171
7272 flagSet.Parse(os.Args[1:])
7373
@@ -95,7 +95,7 @@ func main() {
9595 }
9696
9797 validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile)
98− oauthproxy := NewOauthProxy(opts, validator)
98+ oauthproxy := NewOAuthProxy(opts, validator)
9999
100100 if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
101101 if len(opts.EmailDomains) > 1 {
oauthproxy.go+33−33
@@ -18,7 +18,7 @@ import (
1818 "github.com/bitly/oauth2_proxy/providers"
1919)
2020
21−type OauthProxy struct {
21+type OAuthProxy struct {
2222 CookieSeed string
2323 CookieName string
2424 CookieDomain string
@@ -31,8 +31,8 @@ type OauthProxy struct {
3131 RobotsPath string
3232 PingPath string
3333 SignInPath string
34− OauthStartPath string
35− OauthCallbackPath string
34+ OAuthStartPath string
35+ OAuthCallbackPath string
3636
3737 redirectURL *url.URL // the url to receive requests at
3838 provider providers.Provider
@@ -86,7 +86,7 @@ func NewFileServer(path string, filesystemPath string) (proxy http.Handler) {
8686 return http.StripPrefix(path, http.FileServer(http.Dir(filesystemPath)))
8787}
8888
89−func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
89+func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
9090 serveMux := http.NewServeMux()
9191 for _, u := range opts.proxyURLs {
9292 path := u.Path
@@ -119,7 +119,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
119119 redirectURL := opts.redirectURL
120120 redirectURL.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix)
121121
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)
123123 domain := opts.CookieDomain
124124 if domain == "" {
125125 domain = "<default>"
@@ -141,7 +141,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
141141 }
142142 }
143143
144− return &OauthProxy{
144+ return &OAuthProxy{
145145 CookieName: opts.CookieName,
146146 CookieSeed: opts.CookieSecret,
147147 CookieDomain: opts.CookieDomain,
@@ -154,8 +154,8 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
154154 RobotsPath: "/robots.txt",
155155 PingPath: "/ping",
156156 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),
159159
160160 ProxyPrefix: opts.ProxyPrefix,
161161 provider: opts.provider,
@@ -171,7 +171,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
171171 }
172172}
173173
174−func (p *OauthProxy) GetRedirectURI(host string) string {
174+func (p *OAuthProxy) GetRedirectURI(host string) string {
175175 // default to the request Host if not set
176176 if p.redirectURL.Host != "" {
177177 return p.redirectURL.String()
@@ -189,11 +189,11 @@ func (p *OauthProxy) GetRedirectURI(host string) string {
189189 return u.String()
190190}
191191
192−func (p *OauthProxy) displayCustomLoginForm() bool {
192+func (p *OAuthProxy) displayCustomLoginForm() bool {
193193 return p.HtpasswdFile != nil && p.DisplayHtpasswdForm
194194}
195195
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) {
197197 if code == "" {
198198 return nil, errors.New("missing code")
199199 }
@@ -209,7 +209,7 @@ func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, e
209209 return
210210}
211211
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 {
213213 domain := req.Host
214214 if h, _, err := net.SplitHostPort(domain); err == nil {
215215 domain = h
@@ -235,15 +235,15 @@ func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time
235235 }
236236}
237237
238−func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
238+func (p *OAuthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
239239 http.SetCookie(rw, p.MakeCookie(req, "", time.Hour*-1, time.Now()))
240240}
241241
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) {
243243 http.SetCookie(rw, p.MakeCookie(req, val, p.CookieExpire, time.Now()))
244244}
245245
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) {
247247 var age time.Duration
248248 c, err := req.Cookie(p.CookieName)
249249 if err != nil {
@@ -264,7 +264,7 @@ func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionSt
264264 return session, age, nil
265265}
266266
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 {
268268 value, err := p.provider.CookieForSession(s, p.CookieCipher)
269269 if err != nil {
270270 return err
@@ -273,17 +273,17 @@ func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *p
273273 return nil
274274}
275275
276−func (p *OauthProxy) RobotsTxt(rw http.ResponseWriter) {
276+func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) {
277277 rw.WriteHeader(http.StatusOK)
278278 fmt.Fprintf(rw, "User-agent: *\nDisallow: /")
279279}
280280
281−func (p *OauthProxy) PingPage(rw http.ResponseWriter) {
281+func (p *OAuthProxy) PingPage(rw http.ResponseWriter) {
282282 rw.WriteHeader(http.StatusOK)
283283 fmt.Fprintf(rw, "OK")
284284}
285285
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) {
287287 log.Printf("ErrorPage %d %s %s", code, title, message)
288288 rw.WriteHeader(code)
289289 t := struct {
@@ -298,7 +298,7 @@ func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
298298 p.templates.ExecuteTemplate(rw, "error.html", t)
299299}
300300
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) {
302302 p.ClearCookie(rw, req)
303303 rw.WriteHeader(code)
304304
@@ -325,7 +325,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
325325 p.templates.ExecuteTemplate(rw, "sign_in.html", t)
326326}
327327
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) {
329329 if req.Method != "POST" || p.HtpasswdFile == nil {
330330 return "", false
331331 }
@@ -342,7 +342,7 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
342342 return "", false
343343}
344344
345−func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
345+func (p *OAuthProxy) GetRedirect(req *http.Request) (string, error) {
346346 err := req.ParseForm()
347347
348348 if err != nil {
@@ -358,7 +358,7 @@ func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
358358 return redirect, err
359359}
360360
361−func (p *OauthProxy) IsWhitelistedPath(path string) (ok bool) {
361+func (p *OAuthProxy) IsWhitelistedPath(path string) (ok bool) {
362362 for _, u := range p.compiledRegex {
363363 ok = u.MatchString(path)
364364 if ok {
@@ -376,7 +376,7 @@ func getRemoteAddr(req *http.Request) (s string) {
376376 return
377377}
378378
379−func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
379+func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
380380 switch path := req.URL.Path; {
381381 case path == p.RobotsPath:
382382 p.RobotsTxt(rw)
@@ -386,16 +386,16 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
386386 p.serveMux.ServeHTTP(rw, req)
387387 case path == p.SignInPath:
388388 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)
393393 default:
394394 p.Proxy(rw, req)
395395 }
396396}
397397
398−func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
398+func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
399399 redirect, err := p.GetRedirect(req)
400400 if err != nil {
401401 p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -412,7 +412,7 @@ func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
412412 }
413413}
414414
415−func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
415+func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
416416 redirect, err := p.GetRedirect(req)
417417 if err != nil {
418418 p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -422,7 +422,7 @@ func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
422422 http.Redirect(rw, req, p.provider.GetLoginURL(redirectURI, redirect), 302)
423423}
424424
425−func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
425+func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
426426 remoteAddr := getRemoteAddr(req)
427427
428428 // finish the oauth cycle
@@ -465,7 +465,7 @@ func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
465465 }
466466}
467467
468−func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
468+func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
469469 var saveSession, clearSession, revalidated bool
470470 remoteAddr := getRemoteAddr(req)
471471
@@ -555,7 +555,7 @@ func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
555555 p.serveMux.ServeHTTP(rw, req)
556556}
557557
558−func (p *OauthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
558+func (p *OAuthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
559559 if p.HtpasswdFile == nil {
560560 return nil, nil
561561 }
oauthproxy_test.go+8−8
@@ -80,7 +80,7 @@ func TestRobotsTxt(t *testing.T) {
8080 opts.CookieSecret = "xyzzyplugh"
8181 opts.Validate()
8282
83− proxy := NewOauthProxy(opts, func(string) bool { return true })
83+ proxy := NewOAuthProxy(opts, func(string) bool { return true })
8484 rw := httptest.NewRecorder()
8585 req, _ := http.NewRequest("GET", "/robots.txt", nil)
8686 proxy.ServeHTTP(rw, req)
@@ -144,7 +144,7 @@ func TestBasicAuthPassword(t *testing.T) {
144144 EmailAddress: email_address,
145145 }
146146
147− proxy := NewOauthProxy(opts, func(email string) bool {
147+ proxy := NewOAuthProxy(opts, func(email string) bool {
148148 return email == email_address
149149 })
150150
@@ -199,7 +199,7 @@ func (tp *TestProvider) ValidateSessionState(session *providers.SessionState) bo
199199
200200type PassAccessTokenTest struct {
201201 provider_server *httptest.Server
202− proxy *OauthProxy
202+ proxy *OAuthProxy
203203 opts *Options
204204}
205205
@@ -265,7 +265,7 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes
265265 EmailAddress: email_address,
266266 }
267267
268− t.proxy = NewOauthProxy(t.opts, func(email string) bool {
268+ t.proxy = NewOAuthProxy(t.opts, func(email string) bool {
269269 return email == email_address
270270 })
271271 return t
@@ -360,7 +360,7 @@ func TestDoNotForwardAccessTokenUpstream(t *testing.T) {
360360
361361type SignInPageTest struct {
362362 opts *Options
363− proxy *OauthProxy
363+ proxy *OAuthProxy
364364 sign_in_regexp *regexp.Regexp
365365}
366366
@@ -375,7 +375,7 @@ func NewSignInPageTest() *SignInPageTest {
375375 sip_test.opts.ClientSecret = "xyzzyplugh"
376376 sip_test.opts.Validate()
377377
378− sip_test.proxy = NewOauthProxy(sip_test.opts, func(email string) bool {
378+ sip_test.proxy = NewOAuthProxy(sip_test.opts, func(email string) bool {
379379 return true
380380 })
381381 sip_test.sign_in_regexp = regexp.MustCompile(signInRedirectPattern)
@@ -425,7 +425,7 @@ func TestSignInPageDirectAccessRedirectsToRoot(t *testing.T) {
425425
426426type ProcessCookieTest struct {
427427 opts *Options
428− proxy *OauthProxy
428+ proxy *OAuthProxy
429429 rw *httptest.ResponseRecorder
430430 req *http.Request
431431 provider TestProvider
@@ -449,7 +449,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts) *ProcessCookieTest {
449449 pc_test.opts.CookieRefresh = time.Hour
450450 pc_test.opts.Validate()
451451
452− pc_test.proxy = NewOauthProxy(pc_test.opts, func(email string) bool {
452+ pc_test.proxy = NewOAuthProxy(pc_test.opts, func(email string) bool {
453453 return pc_test.validate_user
454454 })
455455 pc_test.proxy.provider = &TestProvider{