Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.08 KB

basic-auth.md

File metadata and controls

56 lines (43 loc) · 1.08 KB

+++ title = "Basic Auth Middleware" description = "Basic auth middleware for Echo" [menu.main] name = "Basic Auth" parent = "middleware" +++

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, error) {
	if username == "joe" && password == "secret" {
		return true, nil
	}
	return false, nil
}))

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

  // Realm is a string to define realm attribute of BasicAuth.
  // Default value "Restricted".
  Realm string
}

Default Configuration

DefaultBasicAuthConfig = BasicAuthConfig{
	Skipper: DefaultSkipper,
}