github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/pkg/jwt/guard.go (about) 1 package jwt 2 3 import ( 4 "time" 5 6 "github.com/hellofresh/janus/pkg/config" 7 ) 8 9 // Guard struct 10 type Guard struct { 11 ParserConfig 12 13 // Duration that a jwt token is valid. Optional, defaults to one hour. 14 Timeout time.Duration 15 16 // SigningMethod defines new token signing algorithm/key pair. 17 SigningMethod SigningMethod 18 19 // This field allows clients to refresh their token until MaxRefresh has passed. 20 // Note that clients can refresh their token in the last moment of MaxRefresh. 21 // This means that the maximum validity timespan for a token is MaxRefresh + Timeout. 22 // Optional, defaults to 0 meaning not refreshable. 23 MaxRefresh time.Duration 24 } 25 26 // NewGuard creates a new instance of Guard with default handlers 27 func NewGuard(cred config.Credentials) Guard { 28 return Guard{ 29 ParserConfig: ParserConfig{ 30 SigningMethods: []SigningMethod{{Alg: cred.Algorithm, Key: cred.Secret}}, 31 TokenLookup: "header:Authorization", 32 }, 33 SigningMethod: SigningMethod{Alg: cred.Algorithm, Key: cred.Secret}, 34 Timeout: cred.Timeout, 35 MaxRefresh: time.Hour * 24, 36 } 37 }