Skip to content

Commit

Permalink
always set cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Sep 15, 2021
1 parent 3d4ee19 commit b2d53b9
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions proxy/pkg/middleware/selector_cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,25 @@ func (m selectorCookie) ServeHTTP(w http.ResponseWriter, req *http.Request) {
selectorCookieName = m.policySelector.Claims.SelectorCookieName
}

_, err := req.Cookie(selectorCookieName)
if err != nil {
// no cookie there - try to add one
if oidc.FromContext(req.Context()) != nil {
// update cookie
if oidc.FromContext(req.Context()) != nil {

selectorFunc, err := policy.LoadSelector(&m.policySelector)
if err != nil {
m.logger.Err(err)
}
selectorFunc, err := policy.LoadSelector(&m.policySelector)
if err != nil {
m.logger.Err(err)
}

selector, err := selectorFunc(req)
if err != nil {
m.logger.Err(err)
}
selector, err := selectorFunc(req)
if err != nil {
m.logger.Err(err)
}

cookie := http.Cookie{
Name: selectorCookieName,
Value: selector,
Domain: req.Host,
Path: "/",
MaxAge: 60 * 60,
HttpOnly: true,
}
http.SetCookie(w, &cookie)
cookie := http.Cookie{
Name: selectorCookieName,
Value: selector,
Path: "/",
}
http.SetCookie(w, &cookie)
}

m.next.ServeHTTP(w, req)
Expand Down

0 comments on commit b2d53b9

Please sign in to comment.