Skip to content

Commit

Permalink
*: rename Oauth to OAuth
Browse files Browse the repository at this point in the history
Be consistent with Go capitalization styling and use a single way of
spelling this across the tree.
  • Loading branch information
Brandon Philips authored and Ruta Sakalauskaite committed Jan 21, 2016
1 parent 66c7f49 commit d89ed08
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func main() {
flagSet.String("redeem-url", "", "Token redemption endpoint")
flagSet.String("profile-url", "", "Profile access endpoint")
flagSet.String("validate-url", "", "Access token validation endpoint")
flagSet.String("scope", "", "Oauth scope specification")
flagSet.String("approval-prompt", "force", "Oauth approval_prompt")
flagSet.String("scope", "", "OAuth scope specification")
flagSet.String("approval-prompt", "force", "OAuth approval_prompt")

flagSet.Parse(os.Args[1:])

Expand Down Expand Up @@ -95,7 +95,7 @@ func main() {
}

validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile)
oauthproxy := NewOauthProxy(opts, validator)
oauthproxy := NewOAuthProxy(opts, validator)

if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
if len(opts.EmailDomains) > 1 {
Expand Down
66 changes: 33 additions & 33 deletions oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/bitly/oauth2_proxy/providers"
)

type OauthProxy struct {
type OAuthProxy struct {
CookieSeed string
CookieName string
CookieDomain string
Expand All @@ -31,8 +31,8 @@ type OauthProxy struct {
RobotsPath string
PingPath string
SignInPath string
OauthStartPath string
OauthCallbackPath string
OAuthStartPath string
OAuthCallbackPath string

redirectURL *url.URL // the url to receive requests at
provider providers.Provider
Expand Down Expand Up @@ -86,7 +86,7 @@ func NewFileServer(path string, filesystemPath string) (proxy http.Handler) {
return http.StripPrefix(path, http.FileServer(http.Dir(filesystemPath)))
}

func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
serveMux := http.NewServeMux()
for _, u := range opts.proxyURLs {
path := u.Path
Expand Down Expand Up @@ -119,7 +119,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
redirectURL := opts.redirectURL
redirectURL.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix)

log.Printf("OauthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID)
log.Printf("OAuthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID)
domain := opts.CookieDomain
if domain == "" {
domain = "<default>"
Expand All @@ -141,7 +141,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
}
}

return &OauthProxy{
return &OAuthProxy{
CookieName: opts.CookieName,
CookieSeed: opts.CookieSecret,
CookieDomain: opts.CookieDomain,
Expand All @@ -154,8 +154,8 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
RobotsPath: "/robots.txt",
PingPath: "/ping",
SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix),
OauthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
OauthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
OAuthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),

ProxyPrefix: opts.ProxyPrefix,
provider: opts.provider,
Expand All @@ -171,7 +171,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
}
}

func (p *OauthProxy) GetRedirectURI(host string) string {
func (p *OAuthProxy) GetRedirectURI(host string) string {
// default to the request Host if not set
if p.redirectURL.Host != "" {
return p.redirectURL.String()
Expand All @@ -189,11 +189,11 @@ func (p *OauthProxy) GetRedirectURI(host string) string {
return u.String()
}

func (p *OauthProxy) displayCustomLoginForm() bool {
func (p *OAuthProxy) displayCustomLoginForm() bool {
return p.HtpasswdFile != nil && p.DisplayHtpasswdForm
}

func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) {
func (p *OAuthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) {
if code == "" {
return nil, errors.New("missing code")
}
Expand All @@ -209,7 +209,7 @@ func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, e
return
}

func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
func (p *OAuthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
domain := req.Host
if h, _, err := net.SplitHostPort(domain); err == nil {
domain = h
Expand All @@ -235,15 +235,15 @@ func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time
}
}

func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
func (p *OAuthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
http.SetCookie(rw, p.MakeCookie(req, "", time.Hour*-1, time.Now()))
}

func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
func (p *OAuthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
http.SetCookie(rw, p.MakeCookie(req, val, p.CookieExpire, time.Now()))
}

func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) {
func (p *OAuthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) {
var age time.Duration
c, err := req.Cookie(p.CookieName)
if err != nil {
Expand All @@ -264,7 +264,7 @@ func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionSt
return session, age, nil
}

func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error {
func (p *OAuthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error {
value, err := p.provider.CookieForSession(s, p.CookieCipher)
if err != nil {
return err
Expand All @@ -273,17 +273,17 @@ func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *p
return nil
}

func (p *OauthProxy) RobotsTxt(rw http.ResponseWriter) {
func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) {
rw.WriteHeader(http.StatusOK)
fmt.Fprintf(rw, "User-agent: *\nDisallow: /")
}

func (p *OauthProxy) PingPage(rw http.ResponseWriter) {
func (p *OAuthProxy) PingPage(rw http.ResponseWriter) {
rw.WriteHeader(http.StatusOK)
fmt.Fprintf(rw, "OK")
}

func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
log.Printf("ErrorPage %d %s %s", code, title, message)
rw.WriteHeader(code)
t := struct {
Expand All @@ -298,7 +298,7 @@ func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
p.templates.ExecuteTemplate(rw, "error.html", t)
}

func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
p.ClearCookie(rw, req)
rw.WriteHeader(code)

Expand All @@ -325,7 +325,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
p.templates.ExecuteTemplate(rw, "sign_in.html", t)
}

func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {
func (p *OAuthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {
if req.Method != "POST" || p.HtpasswdFile == nil {
return "", false
}
Expand All @@ -342,7 +342,7 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
return "", false
}

func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
func (p *OAuthProxy) GetRedirect(req *http.Request) (string, error) {
err := req.ParseForm()

if err != nil {
Expand All @@ -358,7 +358,7 @@ func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
return redirect, err
}

func (p *OauthProxy) IsWhitelistedPath(path string) (ok bool) {
func (p *OAuthProxy) IsWhitelistedPath(path string) (ok bool) {
for _, u := range p.compiledRegex {
ok = u.MatchString(path)
if ok {
Expand All @@ -376,7 +376,7 @@ func getRemoteAddr(req *http.Request) (s string) {
return
}

func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
switch path := req.URL.Path; {
case path == p.RobotsPath:
p.RobotsTxt(rw)
Expand All @@ -386,16 +386,16 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
p.serveMux.ServeHTTP(rw, req)
case path == p.SignInPath:
p.SignIn(rw, req)
case path == p.OauthStartPath:
p.OauthStart(rw, req)
case path == p.OauthCallbackPath:
p.OauthCallback(rw, req)
case path == p.OAuthStartPath:
p.OAuthStart(rw, req)
case path == p.OAuthCallbackPath:
p.OAuthCallback(rw, req)
default:
p.Proxy(rw, req)
}
}

func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
redirect, err := p.GetRedirect(req)
if err != nil {
p.ErrorPage(rw, 500, "Internal Error", err.Error())
Expand All @@ -412,7 +412,7 @@ func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
}
}

func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
redirect, err := p.GetRedirect(req)
if err != nil {
p.ErrorPage(rw, 500, "Internal Error", err.Error())
Expand All @@ -422,7 +422,7 @@ func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
http.Redirect(rw, req, p.provider.GetLoginURL(redirectURI, redirect), 302)
}

func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
remoteAddr := getRemoteAddr(req)

// finish the oauth cycle
Expand Down Expand Up @@ -465,7 +465,7 @@ func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
}
}

func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
var saveSession, clearSession, revalidated bool
remoteAddr := getRemoteAddr(req)

Expand Down Expand Up @@ -555,7 +555,7 @@ func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
p.serveMux.ServeHTTP(rw, req)
}

func (p *OauthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
func (p *OAuthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
if p.HtpasswdFile == nil {
return nil, nil
}
Expand Down
16 changes: 8 additions & 8 deletions oauthproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRobotsTxt(t *testing.T) {
opts.CookieSecret = "xyzzyplugh"
opts.Validate()

proxy := NewOauthProxy(opts, func(string) bool { return true })
proxy := NewOAuthProxy(opts, func(string) bool { return true })
rw := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/robots.txt", nil)
proxy.ServeHTTP(rw, req)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestBasicAuthPassword(t *testing.T) {
EmailAddress: email_address,
}

proxy := NewOauthProxy(opts, func(email string) bool {
proxy := NewOAuthProxy(opts, func(email string) bool {
return email == email_address
})

Expand Down Expand Up @@ -199,7 +199,7 @@ func (tp *TestProvider) ValidateSessionState(session *providers.SessionState) bo

type PassAccessTokenTest struct {
provider_server *httptest.Server
proxy *OauthProxy
proxy *OAuthProxy
opts *Options
}

Expand Down Expand Up @@ -265,7 +265,7 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes
EmailAddress: email_address,
}

t.proxy = NewOauthProxy(t.opts, func(email string) bool {
t.proxy = NewOAuthProxy(t.opts, func(email string) bool {
return email == email_address
})
return t
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestDoNotForwardAccessTokenUpstream(t *testing.T) {

type SignInPageTest struct {
opts *Options
proxy *OauthProxy
proxy *OAuthProxy
sign_in_regexp *regexp.Regexp
}

Expand All @@ -375,7 +375,7 @@ func NewSignInPageTest() *SignInPageTest {
sip_test.opts.ClientSecret = "xyzzyplugh"
sip_test.opts.Validate()

sip_test.proxy = NewOauthProxy(sip_test.opts, func(email string) bool {
sip_test.proxy = NewOAuthProxy(sip_test.opts, func(email string) bool {
return true
})
sip_test.sign_in_regexp = regexp.MustCompile(signInRedirectPattern)
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestSignInPageDirectAccessRedirectsToRoot(t *testing.T) {

type ProcessCookieTest struct {
opts *Options
proxy *OauthProxy
proxy *OAuthProxy
rw *httptest.ResponseRecorder
req *http.Request
provider TestProvider
Expand All @@ -449,7 +449,7 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts) *ProcessCookieTest {
pc_test.opts.CookieRefresh = time.Hour
pc_test.opts.Validate()

pc_test.proxy = NewOauthProxy(pc_test.opts, func(email string) bool {
pc_test.proxy = NewOAuthProxy(pc_test.opts, func(email string) bool {
return pc_test.validate_user
})
pc_test.proxy.provider = &TestProvider{
Expand Down

0 comments on commit d89ed08

Please sign in to comment.