summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/middleware/basic_auth.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-06-06 00:01:05 +0200
committerWim <wim@42.be>2017-06-06 00:04:18 +0200
commit3a183cb218c6812964a70d2e75884ad7071d9c0c (patch)
treeee0d2492c27e84ace88acfcfdc533545f42ccb21 /vendor/github.com/labstack/echo/middleware/basic_auth.go
parent2eecaccd1c77e8990a80e6b4b6ad6b13a9c95896 (diff)
downloadmatterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.tar.gz
matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.tar.bz2
matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.zip
Update vendor
Diffstat (limited to 'vendor/github.com/labstack/echo/middleware/basic_auth.go')
-rw-r--r--vendor/github.com/labstack/echo/middleware/basic_auth.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/vendor/github.com/labstack/echo/middleware/basic_auth.go b/vendor/github.com/labstack/echo/middleware/basic_auth.go
index e98a87e3..c1f34c8f 100644
--- a/vendor/github.com/labstack/echo/middleware/basic_auth.go
+++ b/vendor/github.com/labstack/echo/middleware/basic_auth.go
@@ -2,6 +2,7 @@ package middleware
import (
"encoding/base64"
+ "strconv"
"github.com/labstack/echo"
)
@@ -15,20 +16,26 @@ type (
// 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
}
// BasicAuthValidator defines a function to validate BasicAuth credentials.
- BasicAuthValidator func(string, string, echo.Context) bool
+ BasicAuthValidator func(string, string, echo.Context) (bool, error)
)
const (
- basic = "Basic"
+ basic = "Basic"
+ defaultRealm = "Restricted"
)
var (
// DefaultBasicAuthConfig is the default BasicAuth middleware config.
DefaultBasicAuthConfig = BasicAuthConfig{
Skipper: DefaultSkipper,
+ Realm: defaultRealm,
}
)
@@ -52,6 +59,9 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
if config.Skipper == nil {
config.Skipper = DefaultBasicAuthConfig.Skipper
}
+ if config.Realm == "" {
+ config.Realm = defaultRealm
+ }
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
@@ -71,15 +81,25 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
for i := 0; i < len(cred); i++ {
if cred[i] == ':' {
// Verify credentials
- if config.Validator(cred[:i], cred[i+1:], c) {
+ valid, err := config.Validator(cred[:i], cred[i+1:], c)
+ if err != nil {
+ return err
+ } else if valid {
return next(c)
}
}
}
}
+ realm := ""
+ if config.Realm == defaultRealm {
+ realm = defaultRealm
+ } else {
+ realm = strconv.Quote(config.Realm)
+ }
+
// Need to return `401` for browsers to pop-up login box.
- c.Response().Header().Set(echo.HeaderWWWAuthenticate, basic+" realm=Restricted")
+ c.Response().Header().Set(echo.HeaderWWWAuthenticate, basic+" realm="+realm)
return echo.ErrUnauthorized
}
}