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