check token expiry
This commit is contained in:
parent
d1d762aa83
commit
a40d20dcdb
2 changed files with 9 additions and 2 deletions
|
@ -60,12 +60,20 @@ func (s *session) GetLogin(r *http.Request) *common.Token {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &common.Token{
|
token := &common.Token{
|
||||||
Kind: claims["kind"].(string),
|
Kind: claims["kind"].(string),
|
||||||
Login: claims["user"].(string),
|
Login: claims["user"].(string),
|
||||||
Label: claims["label"].(string),
|
Label: claims["label"].(string),
|
||||||
Issued: int64(claims["date"].(float64)),
|
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
|
// getToken is a helper function that extracts the token
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
Loading…
Reference in a new issue