File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFunc {
119
119
config .CookieSecure = true
120
120
}
121
121
122
- extractors , err := createExtractors (config .TokenLookup , "" )
122
+ extractors , err := CreateExtractors (config .TokenLookup )
123
123
if err != nil {
124
124
panic (err )
125
125
}
Original file line number Diff line number Diff line change @@ -24,6 +24,26 @@ var errFormExtractorValueMissing = errors.New("missing value in the form")
24
24
// ValuesExtractor defines a function for extracting values (keys/tokens) from the given context.
25
25
type ValuesExtractor func (c echo.Context ) ([]string , error )
26
26
27
+ // CreateExtractors creates ValuesExtractors from given lookups.
28
+ // Lookups is a string in the form of "<source>:<name>" or "<source>:<name>,<source>:<name>" that is used
29
+ // to extract key from the request.
30
+ // Possible values:
31
+ // - "header:<name>" or "header:<name>:<cut-prefix>"
32
+ // `<cut-prefix>` is argument value to cut/trim prefix of the extracted value. This is useful if header
33
+ // value has static prefix like `Authorization: <auth-scheme> <authorisation-parameters>` where part that we
34
+ // want to cut is `<auth-scheme> ` note the space at the end.
35
+ // In case of basic authentication `Authorization: Basic <credentials>` prefix we want to remove is `Basic `.
36
+ // - "query:<name>"
37
+ // - "param:<name>"
38
+ // - "form:<name>"
39
+ // - "cookie:<name>"
40
+ //
41
+ // Multiple sources example:
42
+ // - "header:Authorization,header:X-Api-Key"
43
+ func CreateExtractors (lookups string ) ([]ValuesExtractor , error ) {
44
+ return createExtractors (lookups , "" )
45
+ }
46
+
27
47
func createExtractors (lookups string , authScheme string ) ([]ValuesExtractor , error ) {
28
48
if lookups == "" {
29
49
return nil , nil
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ func TestCreateExtractors(t *testing.T) {
110
110
setPathParams (c , tc .givenPathParams )
111
111
}
112
112
113
- extractors , err := createExtractors (tc .whenLoopups , "" )
113
+ extractors , err := CreateExtractors (tc .whenLoopups )
114
114
if tc .expectCreateError != "" {
115
115
assert .EqualError (t , err , tc .expectCreateError )
116
116
return
You can’t perform that action at this time.
0 commit comments