Skip to content

Commit

Permalink
remove cookie fix (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
simongottschlag authored Feb 8, 2019
1 parent 0400071 commit 892142a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
8 changes: 4 additions & 4 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func ValidateRequestHandler(w http.ResponseWriter, r *http.Request) {
}

w.Header().Add(cfg.Cfg.Headers.User, claims.Username)
if cfg.Get("Headers.IDToken") != "" {
w.Header().Add(cfg.Get("Headers.IDToken"), claims.IDToken)
if cfg.Cfg.Headers.IDToken != "" {
w.Header().Add(cfg.Cfg.Headers.IDToken, claims.IDToken)
}
if cfg.Get("Headers.AccessToken") != "" {
w.Header().Add(cfg.Get("Headers.AccessToken"), claims.AccessToken)
if cfg.Cfg.Headers.AccessToken != "" {
w.Header().Add(cfg.Cfg.Headers.AccessToken, claims.AccessToken)
}
w.Header().Add(cfg.Cfg.Headers.Success, "true")
log.WithFields(log.Fields{cfg.Cfg.Headers.User: w.Header().Get(cfg.Cfg.Headers.User)}).Debug("response header")
Expand Down
10 changes: 0 additions & 10 deletions pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,6 @@ func Get(key string) string {
return viper.GetString(key)
}

// GetInt int value for key
func GetInt(key string) int {
return viper.GetInt(key)
}

// GetBool bool value for key
func GetBool(key string) bool {
return viper.GetBool(key)
}

// BasicTest just a quick sanity check to see if the config is sound
func BasicTest() error {
for _, opt := range RequiredOptions {
Expand Down
17 changes: 8 additions & 9 deletions pkg/cookie/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
"github.com/vouch/vouch-proxy/pkg/domains"
)

var defaultMaxAge = cfg.GetInt("JWT.MaxAge") * 60

var defaultMaxAge = cfg.Cfg.JWT.MaxAge * 60

// SetCookie http
func SetCookie(w http.ResponseWriter, r *http.Request, val string) {
Expand All @@ -25,25 +24,25 @@ func setCookie(w http.ResponseWriter, r *http.Request, val string, maxAge int) {
}
domain := domains.Matches(r.Host)
// Allow overriding the cookie domain in the config file
if cfg.Get("Cookie.Domain") != "" {
domain = cfg.Get("Cookie.Domain")
if cfg.Cfg.Cookie.Domain != "" {
domain = cfg.Cfg.Cookie.Domain
log.Debugf("setting the cookie domain to %v", domain)
}
// log.Debugf("cookie %s expires %d", cfg.Cfg.Cookie.Name, expires)
http.SetCookie(w, &http.Cookie{
Name: cfg.Get("Cookie.Name"),
Name: cfg.Cfg.Cookie.Name,
Value: val,
Path: "/",
Domain: domain,
MaxAge: maxAge,
Secure: cfg.GetBool("Cookie.Secure"),
HttpOnly: cfg.GetBool("Cookie.HTTPOnly"),
Secure: cfg.Cfg.Cookie.Secure,
HttpOnly: cfg.Cfg.Cookie.HTTPOnly,
})
}

// Cookie get the vouch jwt cookie
func Cookie(r *http.Request) (string, error) {
cookie, err := r.Cookie(cfg.Get("Cookie.Name"))
cookie, err := r.Cookie(cfg.Cfg.Cookie.Name)
if err != nil {
return "", err
}
Expand All @@ -52,7 +51,7 @@ func Cookie(r *http.Request) (string, error) {
}

log.WithFields(log.Fields{
"cookieName": cfg.Get("Cookie.Name"),
"cookieName": cfg.Cfg.Cookie.Name,
"cookieValue": cookie.Value,
}).Debug("cookie")
return cookie.Value, err
Expand Down

0 comments on commit 892142a

Please sign in to comment.