-
Notifications
You must be signed in to change notification settings - Fork 205
/
option.go
46 lines (41 loc) · 1.18 KB
/
option.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
package jwtmiddleware
// Option is how options for the JWTMiddleware are set up.
type Option func(*JWTMiddleware)
// WithCredentialsOptional sets up if credentials are
// optional or not. If set to true then an empty token
// will be considered valid.
//
// Default value: false.
func WithCredentialsOptional(value bool) Option {
return func(m *JWTMiddleware) {
m.credentialsOptional = value
}
}
// WithValidateOnOptions sets up if OPTIONS requests
// should have their JWT validated or not.
//
// Default value: true.
func WithValidateOnOptions(value bool) Option {
return func(m *JWTMiddleware) {
m.validateOnOptions = value
}
}
// WithErrorHandler sets the handler which is called
// when we encounter errors in the JWTMiddleware.
// See the ErrorHandler type for more information.
//
// Default value: DefaultErrorHandler.
func WithErrorHandler(h ErrorHandler) Option {
return func(m *JWTMiddleware) {
m.errorHandler = h
}
}
// WithTokenExtractor sets up the function which extracts
// the JWT to be validated from the request.
//
// Default value: AuthHeaderTokenExtractor.
func WithTokenExtractor(e TokenExtractor) Option {
return func(m *JWTMiddleware) {
m.tokenExtractor = e
}
}