Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cookies #3

Merged
merged 43 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
332f415
Fix ADFS
simongottschlag Feb 5, 2019
407f658
temp debug cookie domain
simongottschlag Feb 5, 2019
46911c1
temp debug
simongottschlag Feb 5, 2019
aa65c7b
test Cfg
simongottschlag Feb 5, 2019
707eed8
test
simongottschlag Feb 5, 2019
eed8998
test
simongottschlag Feb 5, 2019
0081c8c
test
simongottschlag Feb 5, 2019
7e9f967
pretty print
simongottschlag Feb 5, 2019
0b55ea9
test
simongottschlag Feb 5, 2019
53feba7
add pretty
simongottschlag Feb 5, 2019
aacb434
cookieConfig
simongottschlag Feb 5, 2019
205060e
debug main
simongottschlag Feb 5, 2019
9c80cf7
Merge pull request #2 from simongottschlag/patch-1
simongottschlag Feb 5, 2019
3f2f477
change git repo
simongottschlag Feb 5, 2019
457db07
debug viper
simongottschlag Feb 5, 2019
bffe2fe
test viper in cookie
simongottschlag Feb 5, 2019
b7d070d
change cfg.Cfg to config
simongottschlag Feb 5, 2019
6614288
place config before defaultMaxAge
simongottschlag Feb 5, 2019
f580ad5
test resturn Cfg
simongottschlag Feb 5, 2019
303c586
.
simongottschlag Feb 5, 2019
0be0fab
remove return Cfg
simongottschlag Feb 5, 2019
62c9cfe
debug unmarshal key
simongottschlag Feb 5, 2019
f1299fa
change domain to config instead of cfg.Cfg
simongottschlag Feb 5, 2019
9668c78
change back
simongottschlag Feb 5, 2019
1e825ec
debug temp
simongottschlag Feb 5, 2019
fb88825
debug cfg.go
simongottschlag Feb 5, 2019
040c0a1
.
simongottschlag Feb 5, 2019
690ae2d
test cfg.init
simongottschlag Feb 5, 2019
a823028
move cfg.init()
simongottschlag Feb 5, 2019
f4fcba9
test cfg.Get
simongottschlag Feb 5, 2019
832691e
fix everything
simongottschlag Feb 5, 2019
931ca4d
fix everything again
simongottschlag Feb 5, 2019
5229f06
test?
simongottschlag Feb 5, 2019
86c0025
switch to unint
simongottschlag Feb 5, 2019
c9d6a47
change to int
simongottschlag Feb 5, 2019
919a49d
fix
simongottschlag Feb 5, 2019
49e8390
test
simongottschlag Feb 5, 2019
44581b2
lalalal
simongottschlag Feb 5, 2019
248ba83
fix
simongottschlag Feb 5, 2019
a596bc1
remove debug
simongottschlag Feb 5, 2019
da1c172
restore
simongottschlag Feb 5, 2019
f78b05b
remove
simongottschlag Feb 5, 2019
045efa3
just fix cookies
simongottschlag Feb 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ func Get(key string) string {
return viper.GetString(key)
}

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

// Get 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: 9 additions & 8 deletions pkg/cookie/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"github.com/vouch/vouch-proxy/pkg/domains"
)

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


// SetCookie http
func SetCookie(w http.ResponseWriter, r *http.Request, val string) {
Expand All @@ -24,25 +25,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.Cfg.Cookie.Domain != "" {
domain = cfg.Cfg.Cookie.Domain
if cfg.Get("Cookie.Domain") != "" {
domain = cfg.Get("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.Cfg.Cookie.Name,
Name: cfg.Get("Cookie.Name"),
Value: val,
Path: "/",
Domain: domain,
MaxAge: maxAge,
Secure: cfg.Cfg.Cookie.Secure,
HttpOnly: cfg.Cfg.Cookie.HTTPOnly,
Secure: cfg.GetBool("Cookie.Secure"),
HttpOnly: cfg.GetBool("Cookie.HTTPOnly"),
})
}

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

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