Skip to content

Commit

Permalink
Remove methods again
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Aman committed Jan 19, 2019
1 parent 35457be commit 76f6612
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions internal/proxy/oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,97 +479,6 @@ func (p *OAuthProxy) redeemCode(host, code string) (*sessions.SessionState, erro
return s, nil
}

// MakeSessionCookie constructs a session cookie given the request, an expiration time and the current time.
func (p *OAuthProxy) MakeSessionCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
return p.makeCookie(req, p.CookieName, value, expiration, now)
}

// MakeCSRFCookie creates a CSRF cookie given the request, an expiration time, and the current time.
func (p *OAuthProxy) MakeCSRFCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
return p.makeCookie(req, p.CSRFCookieName, value, expiration, now)
}

func (p *OAuthProxy) makeCookie(req *http.Request, name string, value string, expiration time.Duration, now time.Time) *http.Cookie {
logger := log.NewLogEntry()

domain := req.Host
if h, _, err := net.SplitHostPort(domain); err == nil {
domain = h
}
if p.CookieDomain != "" {
if !strings.HasSuffix(domain, p.CookieDomain) {
logger.WithRequestHost(domain).WithCookieDomain(p.CookieDomain).Warn(
"using configured cookie domain")
}
domain = p.CookieDomain
}

return &http.Cookie{
Name: name,
Value: value,
Path: "/",
Domain: domain,
HttpOnly: p.CookieHTTPOnly,
Secure: p.CookieSecure,
Expires: now.Add(expiration),
}
}

// ClearCSRFCookie clears the CSRF cookie from the request
func (p *OAuthProxy) ClearCSRFCookie(rw http.ResponseWriter, req *http.Request) {
http.SetCookie(rw, p.MakeCSRFCookie(req, "", time.Hour*-1, time.Now()))
}

// SetCSRFCookie sets the CSRFCookie creates a CSRF cookie in a given request
func (p *OAuthProxy) SetCSRFCookie(rw http.ResponseWriter, req *http.Request, val string) {
http.SetCookie(rw, p.MakeCSRFCookie(req, val, p.CookieExpire, time.Now()))
}

// ClearSessionCookie clears the session cookie from a request
func (p *OAuthProxy) ClearSessionCookie(rw http.ResponseWriter, req *http.Request) {
http.SetCookie(rw, p.MakeSessionCookie(req, "", time.Hour*-1, time.Now()))
}

// SetSessionCookie creates a sesion cookie based on the value and the expiration time.
func (p *OAuthProxy) SetSessionCookie(rw http.ResponseWriter, req *http.Request, val string) {
http.SetCookie(rw, p.MakeSessionCookie(req, val, p.CookieExpire, time.Now()))
}

// LoadCookiedSession returns a SessionState from the cookie in the request.
func (p *OAuthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, error) {
logger := log.NewLogEntry().WithRemoteAddress(getRemoteAddr(req))

c, err := req.Cookie(p.CookieName)
if err != nil {
// always http.ErrNoCookie
return nil, err
}

session, err := providers.UnmarshalSession(c.Value, p.CookieCipher)
if err != nil {
tags := []string{"error:unmarshaling_session"}
p.StatsdClient.Incr("application_error", tags, 1.0)
logger.Error(err, "unable to unmarshal session")
return nil, ErrInvalidSession
}

return session, nil
}

// SaveSession saves a session state to a request cookie.
func (p *OAuthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error {
value, err := providers.MarshalSession(s, p.CookieCipher)
if err != nil {
return err
}

p.SetSessionCookie(rw, req, value)
logger := log.NewLogEntry().WithRemoteAddress(getRemoteAddr(req))
logger.Printf("session saved: %v", s)

return nil
}

// RobotsTxt sets the User-Agent header in the response to be "Disallow"
func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter, _ *http.Request) {
rw.WriteHeader(http.StatusOK)
Expand Down

0 comments on commit 76f6612

Please sign in to comment.