Skip to content

Commit

Permalink
Add resource to redirect query
Browse files Browse the repository at this point in the history
  • Loading branch information
simongottschlag committed Feb 8, 2019
1 parent 6e00591 commit ed8ef3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
18 changes: 8 additions & 10 deletions pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,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 Expand Up @@ -416,6 +406,9 @@ func setDefaults() {
} else if GenOAuth.Provider == Providers.GitHub {
setDefaultsGitHub()
configureOAuthClient()
} else if GenOAuth.Provider == Providers.ADFS {
setDefaultsADFS()
configureOAuthClient()
} else {
configureOAuthClient()
}
Expand All @@ -441,6 +434,11 @@ func setDefaultsGoogle() {
}
}

func setDefaultsADFS() {
log.Info("configuring ADFS OAuth")
OAuthopts = oauth2.SetAuthURLParam("resource", GenOAuth.RedirectURL) // Needed or all claims won't be included
}

func setDefaultsGitHub() {
// log.Info("configuring GitHub OAuth")
if GenOAuth.AuthURL == "" {
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 ed8ef3b

Please sign in to comment.