caddyauth: Simplify error placeholder setting for authentication provider

This commit is contained in:
Steffen Busch 2025-03-29 16:38:56 +01:00
parent c500c55375
commit c3feef49aa

View File

@ -17,7 +17,6 @@ package caddyauth
import (
"fmt"
"net/http"
"strings"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
@ -38,6 +37,10 @@ func init() {
// `{http.auth.user.*}` placeholders may be set for any authentication
// modules that provide user metadata.
//
// In case of an error, the placeholder `{http.auth.<provider>.error}`
// will be set to the error message returned by the authentication
// provider.
//
// Its API is still experimental and may be subject to change.
type Authentication struct {
// A set of authentication providers. If none are specified,
@ -84,8 +87,7 @@ func (a Authentication) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
}
// Set the error from the authentication provider in a placeholder,
// so it can be used in the handle_errors directive.
sanitizedProvName := strings.ReplaceAll(provName, " ", "_")
repl.Set(fmt.Sprintf("http.auth.%s.error", sanitizedProvName), err.Error())
repl.Set("http.auth."+provName+".error", err.Error())
continue
}
if authed {