@@ -33,6 +33,7 @@ type OauthProxy struct {
3333 CookieSecure bool
3434 CookieHttpOnly bool
3535 CookieExpire time.Duration
36+ CookieRefresh time.Duration
3637 Validator func(string) bool
3738
3839 redirectUrl *url.URL // the url to receive requests at
@@ -136,6 +137,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
136137 CookieSecure: opts.CookieSecure,
137138 CookieHttpOnly: opts.CookieHttpOnly,
138139 CookieExpire: opts.CookieExpire,
140+ CookieRefresh: opts.CookieRefresh,
139141 Validator: validator,
140142
141143 clientID: opts.ClientID,
@@ -259,10 +261,11 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st
259261}
260262
261263func (p *OauthProxy) ProcessCookie(rw http.ResponseWriter, req *http.Request) (email, user, access_token string, ok bool) {
264+ var value string
265+ var timestamp time.Time
262266 cookie, err := req.Cookie(p.CookieKey)
263267 if err == nil {
264− var value string
265− value, ok = validateCookie(cookie, p.CookieSeed)
268+ value, timestamp, ok = validateCookie(cookie, p.CookieSeed)
266269 if ok {
267270 email, user, access_token, err = parseCookieValue(
268271 value, p.AesCipher)
@@ -270,6 +273,11 @@ func (p *OauthProxy) ProcessCookie(rw http.ResponseWriter, req *http.Request) (e
270273 }
271274 if err != nil {
272275 log.Printf(err.Error())
276+ } else if p.CookieRefresh != time.Duration(0) {
277+ refresh_threshold := time.Now().Add(p.CookieRefresh)
278+ if refresh_threshold.Unix() > timestamp.Unix() {
279+ p.SetCookie(rw, req, value)
280+ }
273281 }
274282 return
275283}