summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/caddyauth
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/caddyauth')
-rw-r--r--modules/caddyhttp/caddyauth/basicauth.go11
-rw-r--r--modules/caddyhttp/caddyauth/caddyauth.go21
-rw-r--r--modules/caddyhttp/caddyauth/caddyfile.go4
-rw-r--r--modules/caddyhttp/caddyauth/hashes.go8
4 files changed, 20 insertions, 24 deletions
diff --git a/modules/caddyhttp/caddyauth/basicauth.go b/modules/caddyhttp/caddyauth/basicauth.go
index 6412d36..8aa44f1 100644
--- a/modules/caddyhttp/caddyauth/basicauth.go
+++ b/modules/caddyhttp/caddyauth/basicauth.go
@@ -28,7 +28,7 @@ func init() {
// HTTPBasicAuth facilitates HTTP basic authentication.
type HTTPBasicAuth struct {
- HashRaw json.RawMessage `json:"hash,omitempty"`
+ HashRaw json.RawMessage `json:"hash,omitempty" caddy:"namespace=http.authentication.hashes inline_key=algorithm"`
AccountList []Account `json:"accounts,omitempty"`
Realm string `json:"realm,omitempty"`
@@ -39,8 +39,8 @@ type HTTPBasicAuth struct {
// CaddyModule returns the Caddy module information.
func (HTTPBasicAuth) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
- Name: "http.handlers.authentication.providers.http_basic",
- New: func() caddy.Module { return new(HTTPBasicAuth) },
+ ID: "http.authentication.providers.http_basic",
+ New: func() caddy.Module { return new(HTTPBasicAuth) },
}
}
@@ -51,12 +51,11 @@ func (hba *HTTPBasicAuth) Provision(ctx caddy.Context) error {
}
// load password hasher
- hashIface, err := ctx.LoadModuleInline("algorithm", "http.handlers.authentication.hashes", hba.HashRaw)
+ hasherIface, err := ctx.LoadModule(hba, "HashRaw")
if err != nil {
return fmt.Errorf("loading password hasher module: %v", err)
}
- hba.Hash = hashIface.(Comparer)
- hba.HashRaw = nil // allow GC to deallocate
+ hba.Hash = hasherIface.(Comparer)
if hba.Hash == nil {
return fmt.Errorf("hash is required")
diff --git a/modules/caddyhttp/caddyauth/caddyauth.go b/modules/caddyhttp/caddyauth/caddyauth.go
index 48d4fba..c79d080 100644
--- a/modules/caddyhttp/caddyauth/caddyauth.go
+++ b/modules/caddyhttp/caddyauth/caddyauth.go
@@ -15,7 +15,6 @@
package caddyauth
import (
- "encoding/json"
"fmt"
"log"
"net/http"
@@ -30,7 +29,7 @@ func init() {
// Authentication is a middleware which provides user authentication.
type Authentication struct {
- ProvidersRaw map[string]json.RawMessage `json:"providers,omitempty"`
+ ProvidersRaw caddy.ModuleMap `json:"providers,omitempty" caddy:"namespace=http.authentication.providers"`
Providers map[string]Authenticator `json:"-"`
}
@@ -38,23 +37,21 @@ type Authentication struct {
// CaddyModule returns the Caddy module information.
func (Authentication) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
- Name: "http.handlers.authentication",
- New: func() caddy.Module { return new(Authentication) },
+ ID: "http.handlers.authentication",
+ New: func() caddy.Module { return new(Authentication) },
}
}
// Provision sets up a.
func (a *Authentication) Provision(ctx caddy.Context) error {
a.Providers = make(map[string]Authenticator)
- for modName, rawMsg := range a.ProvidersRaw {
- val, err := ctx.LoadModule("http.handlers.authentication.providers."+modName, rawMsg)
- if err != nil {
- return fmt.Errorf("loading authentication provider module '%s': %v", modName, err)
- }
- a.Providers[modName] = val.(Authenticator)
+ mods, err := ctx.LoadModule(a, "ProvidersRaw")
+ if err != nil {
+ return fmt.Errorf("loading authentication providers: %v", err)
+ }
+ for modName, modIface := range mods.(map[string]interface{}) {
+ a.Providers[modName] = modIface.(Authenticator)
}
- a.ProvidersRaw = nil // allow GC to deallocate
-
return nil
}
diff --git a/modules/caddyhttp/caddyauth/caddyfile.go b/modules/caddyhttp/caddyauth/caddyfile.go
index 3600324..8a33e6f 100644
--- a/modules/caddyhttp/caddyauth/caddyfile.go
+++ b/modules/caddyhttp/caddyauth/caddyfile.go
@@ -16,8 +16,8 @@ package caddyauth
import (
"encoding/base64"
- "encoding/json"
+ "github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
@@ -97,7 +97,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
}
return Authentication{
- ProvidersRaw: map[string]json.RawMessage{
+ ProvidersRaw: caddy.ModuleMap{
"http_basic": caddyconfig.JSON(ba, nil),
},
}, nil
diff --git a/modules/caddyhttp/caddyauth/hashes.go b/modules/caddyhttp/caddyauth/hashes.go
index 13010db..3ca5116 100644
--- a/modules/caddyhttp/caddyauth/hashes.go
+++ b/modules/caddyhttp/caddyauth/hashes.go
@@ -33,8 +33,8 @@ type BcryptHash struct{}
// CaddyModule returns the Caddy module information.
func (BcryptHash) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
- Name: "http.handlers.authentication.hashes.bcrypt",
- New: func() caddy.Module { return new(BcryptHash) },
+ ID: "http.authentication.hashes.bcrypt",
+ New: func() caddy.Module { return new(BcryptHash) },
}
}
@@ -61,8 +61,8 @@ type ScryptHash struct {
// CaddyModule returns the Caddy module information.
func (ScryptHash) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
- Name: "http.handlers.authentication.hashes.scrypt",
- New: func() caddy.Module { return new(ScryptHash) },
+ ID: "http.authentication.hashes.scrypt",
+ New: func() caddy.Module { return new(ScryptHash) },
}
}