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 {
119119 config .CookieSecure = true
120120 }
121121
122- extractors , err := createExtractors (config .TokenLookup , "" )
122+ extractors , err := CreateExtractors (config .TokenLookup )
123123 if err != nil {
124124 panic (err )
125125 }
Original file line number Diff line number Diff line change @@ -24,6 +24,26 @@ var errFormExtractorValueMissing = errors.New("missing value in the form")
2424// ValuesExtractor defines a function for extracting values (keys/tokens) from the given context.
2525type ValuesExtractor func (c echo.Context ) ([]string , error )
2626
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+
2747func createExtractors (lookups string , authScheme string ) ([]ValuesExtractor , error ) {
2848 if lookups == "" {
2949 return nil , nil
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ func TestCreateExtractors(t *testing.T) {
110110 setPathParams (c , tc .givenPathParams )
111111 }
112112
113- extractors , err := createExtractors (tc .whenLoopups , "" )
113+ extractors , err := CreateExtractors (tc .whenLoopups )
114114 if tc .expectCreateError != "" {
115115 assert .EqualError (t , err , tc .expectCreateError )
116116 return
You can’t perform that action at this time.
0 commit comments