-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoptions.go
65 lines (53 loc) · 1.82 KB
/
options.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package pasetomiddleware
import (
"net/http"
"github.com/o1egl/paseto"
)
// ErrorHandler receives an error and can use that to return an error to the HTTP Request
type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
// TokenExtractor extracts the token from a request and returns that or an error
type TokenExtractor func(r *http.Request) (string, error)
// TokenDecryptor decrypts the encrypted paseto token and puts it in the token and footer pointers.
type TokenDecryptor func(pas string, token *paseto.JSONToken, footer *string) error
// Error handles any errors that occur in the middleware process
func Error(eh ErrorHandler) Option {
return func(p *PasetoMiddleware) {
p.ErrorHandler = eh
}
}
// Extractor extracts the Paseto token from the request.
func Extractor(e TokenExtractor) Option {
return func(p *PasetoMiddleware) {
p.Extractor = e
}
}
// Decryptor decrypts the Paseto token that was retrieved through Extractor
func Decryptor(d TokenDecryptor) Option {
return func(p *PasetoMiddleware) {
p.Decryptor = d
}
}
// CredentialsOptional allows the user to not be authenticated on a path with this middleware.
func CredentialsOptional(o bool) Option {
return func(p *PasetoMiddleware) {
p.CredentialsOptional = o
}
}
// TokenProperty defines where the unencrypted Paseto token should be stored in the context of the request.
func TokenProperty(tk TokenKey) Option {
return func(p *PasetoMiddleware) {
p.TokenProperty = tk
}
}
// FooterProperty defines where the unencrypted Paseto footer should be stored in the context of the request.
func FooterProperty(fk FooterKey) Option {
return func(p *PasetoMiddleware) {
p.FooterProperty = fk
}
}
// Debug defines if the decryption process should be printed to stdout
func Debug(d bool) Option {
return func(p *PasetoMiddleware) {
p.Debug = d
}
}