|
@ -16,11 +16,11 @@ package caddyauth |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"log" |
|
|
|
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2" |
|
|
"github.com/caddyserver/caddy/v2" |
|
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp" |
|
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp" |
|
|
|
|
|
"go.uber.org/zap" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func init() { |
|
|
func init() { |
|
@ -42,6 +42,8 @@ type Authentication struct { |
|
|
ProvidersRaw caddy.ModuleMap `json:"providers,omitempty" caddy:"namespace=http.authentication.providers"` |
|
|
ProvidersRaw caddy.ModuleMap `json:"providers,omitempty" caddy:"namespace=http.authentication.providers"` |
|
|
|
|
|
|
|
|
Providers map[string]Authenticator `json:"-"` |
|
|
Providers map[string]Authenticator `json:"-"` |
|
|
|
|
|
|
|
|
|
|
|
logger *zap.Logger |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// CaddyModule returns the Caddy module information.
|
|
|
// CaddyModule returns the Caddy module information.
|
|
@ -54,6 +56,7 @@ func (Authentication) CaddyModule() caddy.ModuleInfo { |
|
|
|
|
|
|
|
|
// Provision sets up a.
|
|
|
// Provision sets up a.
|
|
|
func (a *Authentication) Provision(ctx caddy.Context) error { |
|
|
func (a *Authentication) Provision(ctx caddy.Context) error { |
|
|
|
|
|
a.logger = ctx.Logger(a) |
|
|
a.Providers = make(map[string]Authenticator) |
|
|
a.Providers = make(map[string]Authenticator) |
|
|
mods, err := ctx.LoadModule(a, "ProvidersRaw") |
|
|
mods, err := ctx.LoadModule(a, "ProvidersRaw") |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -72,7 +75,9 @@ func (a Authentication) ServeHTTP(w http.ResponseWriter, r *http.Request, next c |
|
|
for provName, prov := range a.Providers { |
|
|
for provName, prov := range a.Providers { |
|
|
user, authed, err = prov.Authenticate(w, r) |
|
|
user, authed, err = prov.Authenticate(w, r) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("[ERROR] Authenticating with %s: %v", provName, err) |
|
|
a.logger.Error("auth provider returned error", |
|
|
|
|
|
zap.String("provider", provName), |
|
|
|
|
|
zap.Error(err)) |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
if authed { |
|
|
if authed { |
|
|