1
0
mirror of https://github.com/labstack/echo.git synced 2026-05-18 10:01:24 +02:00
Files
echo/website/content/middleware/basic-auth.md
T
Vishal Rana a2b9836e8c New look (#738)
* docs: edit on github

Signed-off-by: Vishal Rana <vishal.rana@verizon.com>

* updated docs

Signed-off-by: Vishal Rana <vishal.rana@verizon.com>

* cleaner Context#Param

Signed-off-by: Vishal Rana <vishal.rana@verizon.com>

* updated website

Signed-off-by: Vishal Rana <vr@labstack.com>

* updated website

Signed-off-by: Vishal Rana <vr@labstack.com>
2016-11-19 22:13:05 -08:00

1.1 KiB

+++ title = "BasicAuth Middleware" description = "Basic auth middleware for Echo" [menu.side] name = "BasicAuth" parent = "middleware" weight = 5 +++

BasicAuth middleware provides an HTTP basic authentication.

  • For valid credentials it calls the next handler.
  • For invalid credentials, it sends "401 - Unauthorized" response.
  • For empty or invalid Authorization header, it sends "400 - Bad Request" response.

Usage

e := echo.New()
e.Use(middleware.BasicAuth(func(username, password string) bool {
	if username == "joe" && password == "secret" {
		return true
	}
	return false
}))

Custom Configuration

Usage

e := echo.New()
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,
}