mirror of
https://github.com/labstack/echo.git
synced 2025-07-05 00:58:47 +02:00
@ -20,6 +20,7 @@ type (
|
|||||||
// Possible values:
|
// Possible values:
|
||||||
// - "header:<name>"
|
// - "header:<name>"
|
||||||
// - "query:<name>"
|
// - "query:<name>"
|
||||||
|
// - "form:<name>"
|
||||||
KeyLookup string `json:"key_lookup"`
|
KeyLookup string `json:"key_lookup"`
|
||||||
|
|
||||||
// AuthScheme to be used in the Authorization header.
|
// AuthScheme to be used in the Authorization header.
|
||||||
@ -81,6 +82,8 @@ func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFunc {
|
|||||||
switch parts[0] {
|
switch parts[0] {
|
||||||
case "query":
|
case "query":
|
||||||
extractor = keyFromQuery(parts[1])
|
extractor = keyFromQuery(parts[1])
|
||||||
|
case "form":
|
||||||
|
extractor = keyFromForm(parts[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
@ -134,3 +137,14 @@ func keyFromQuery(param string) keyExtractor {
|
|||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keyFromForm returns a `keyExtractor` that extracts key from the form.
|
||||||
|
func keyFromForm(param string) keyExtractor {
|
||||||
|
return func(c echo.Context) (string, error) {
|
||||||
|
key := c.FormValue(param)
|
||||||
|
if key == "" {
|
||||||
|
return "", errors.New("Missing key in the form")
|
||||||
|
}
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user