mirror of
https://github.com/labstack/echo.git
synced 2025-01-20 02:59:54 +02:00
04a7fc65e3
Current method gives type error because `context` variable is not present. Adding the `c echo.Context` for resolving type error.
992 B
992 B
+++ title = "Basic Auth Middleware" description = "Basic auth middleware for Echo" [menu.main] name = "Basic Auth" parent = "middleware" weight = 5 +++
Basic auth middleware provides an HTTP basic authentication.
- For valid credentials it calls the next handler.
- For missing or invalid credentials, it sends "401 - Unauthorized" response.
Usage
e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) bool {
if username == "joe" && password == "secret" {
return true
}
return false
}))
Custom Configuration
Usage
e.Use(middleware.BasicAuthWithConfig(middleware.BasicAuthConfig{}}))
Configuration
BasicAuthConfig struct {
// Skipper defines a function to skip middleware.
Skipper Skipper
// Validator is a function to validate BasicAuth credentials.
// Required.
Validator BasicAuthValidator
}
Default Configuration
DefaultBasicAuthConfig = BasicAuthConfig{
Skipper: defaultSkipper,
}