From a40d20dcdb533784a3da4cb1f700fd05fdd4321c Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 13 Apr 2015 19:07:05 -0700 Subject: [PATCH] check token expiry --- server/session/session.go | 10 +++++++++- server/token.go | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/session/session.go b/server/session/session.go index 072515ce..6061d309 100644 --- a/server/session/session.go +++ b/server/session/session.go @@ -60,12 +60,20 @@ func (s *session) GetLogin(r *http.Request) *common.Token { return nil } - return &common.Token{ + token := &common.Token{ Kind: claims["kind"].(string), Login: claims["user"].(string), Label: claims["label"].(string), Issued: int64(claims["date"].(float64)), } + if token.Kind != common.TokenSess { + return token + } + + if time.Now().UTC().Add(s.expire).Unix() > token.Issued { + return nil + } + return token } // getToken is a helper function that extracts the token diff --git a/server/token.go b/server/token.go index 2eade64b..2cb36a29 100644 --- a/server/token.go +++ b/server/token.go @@ -1,7 +1,6 @@ package server import ( - "errors" "time" "github.com/gin-gonic/gin"