git.iko.soy/typeable/oauth2-proxy
on master help sign in
Added cookie settings
commit6cdf05e7f2723ad734b74755599c70ad5a64b288 authorIgor Dolgiy <i.dolgiy@co.wapstart.ru> dateThu 19 Jun 2014, 18:50 (12 years ago) parent23a89b0
2 files changed+18−3
main.go+2 oauthproxy.go+16−3
main.go+2
@@ -23,6 +23,8 @@ var (
2323 htpasswdFile = flag.String("htpasswd-file", "", "additionally authenticate against a htpasswd file. Entries must be created with \"htpasswd -s\" for SHA encryption")
2424 cookieSecret = flag.String("cookie-secret", "", "the seed string for secure cookies")
2525 cookieDomain = flag.String("cookie-domain", "", "an optional cookie domain to force cookies to")
26+ cookieExpire = flag.Int("cookie-expire", 168 * 60, "expire time for cookie")
27+ cookieSecure = flag.Bool("cookie-secure", false, "HTTPS only cookie")
2628 authenticatedEmailsFile = flag.String("authenticated-emails-file", "", "authenticate against emails via file (one per line)")
2729 googleAppsDomains = StringArray{}
2830 upstreams = StringArray{}
oauthproxy.go+16−3
@@ -184,14 +184,27 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st
184184 if *cookieDomain != "" && strings.HasSuffix(domain, *cookieDomain) {
185185 domain = *cookieDomain
186186 }
187+ need_expire := true
188+ expire := time.Now().Add(time.Duration(*cookieExpire))
189+ if *cookieExpire == 0 {
190+ need_expire = false
191+ }
192+ http_only := true
193+ secure := false
194+ if *cookieSecure {
195+ http_only = false
196+ secure = true
197+ }
187198 cookie := &http.Cookie{
188199 Name: p.CookieKey,
189200 Value: signedCookieValue(p.CookieSeed, p.CookieKey, val),
190201 Path: "/",
191202 Domain: domain,
192− Expires: time.Now().Add(time.Duration(168) * time.Hour), // 7 days
193− HttpOnly: true,
194− // Secure: req. ... ? set if X-Scheme: https ?
203+ HttpOnly: http_only,
204+ Secure: secure,
205+ }
206+ if need_expire {
207+ cookie.Expires = expire
195208 }
196209 http.SetCookie(rw, cookie)
197210}