Implement JWT expiration
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
type (
|
||||
configuration struct {
|
||||
jwtSecret string
|
||||
jwtExpiry int64
|
||||
}
|
||||
)
|
||||
|
||||
@@ -24,4 +25,5 @@ func (c configuration) validate() error {
|
||||
// Flags should be called from main to register flags
|
||||
func Flags() {
|
||||
flag.StringVar(&config.jwtSecret, "auth-jwt-secret", "", "JWT Secret")
|
||||
flag.Int64Var(&config.jwtExpiry, "auth-jwt-expiry", 3600, "JWT Expiration in minutes")
|
||||
}
|
||||
|
||||
+6
-1
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/titpetric/factory/resputil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type jwt struct {
|
||||
@@ -28,7 +29,11 @@ func (t *jwt) Verifier() func(http.Handler) http.Handler {
|
||||
|
||||
func (t *jwt) Encode(identity Identifiable) string {
|
||||
// @todo Set expiry
|
||||
_, jwt, _ := t.tokenAuth.Encode(jwtauth.Claims{}.Set("sub", strconv.FormatUint(identity.GetID(), 10)))
|
||||
claims := jwtauth.Claims{}
|
||||
claims.Set("sub", strconv.FormatUint(identity.GetID(), 10))
|
||||
claims.SetExpiryIn(time.Duration(config.jwtExpiry) * time.Minute)
|
||||
|
||||
_, jwt, _ := t.tokenAuth.Encode(claims)
|
||||
return jwt
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user