Add proxy auth ui

This commit is contained in:
Eduard Gert
2026-02-03 19:05:55 +01:00
parent 92f72bfce6
commit 733ea77c5c
44 changed files with 5479 additions and 13 deletions

View File

@@ -3,9 +3,7 @@ package auth
import (
"context"
"crypto/rand"
_ "embed"
"encoding/base64"
"html/template"
"net"
"net/http"
"sync"
@@ -13,12 +11,10 @@ import (
"google.golang.org/grpc"
"github.com/netbirdio/netbird/proxy/web"
"github.com/netbirdio/netbird/shared/management/proto"
)
//go:embed auth.gohtml
var authTemplate string
type Method string
var (
@@ -91,7 +87,6 @@ func NewMiddleware() *Middleware {
// In the event that no authentication schemes are defined for the domain,
// then the request will also be simply passed through.
func (mw *Middleware) Protect(next http.Handler) http.Handler {
tmpl := template.Must(template.New("auth").Parse(authTemplate))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
host, _, err := net.SplitHostPort(r.Host)
if err != nil {
@@ -141,13 +136,7 @@ func (mw *Middleware) Protect(next http.Handler) http.Handler {
// if none of them intercept the request, then this handler will
// be called and present the user with the authentication page.
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := tmpl.Execute(w, struct {
Methods map[string]string
}{
Methods: methods,
}); err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)
}
web.ServeHTTP(w, r, map[string]any{"methods": methods})
}))
// No authentication succeeded. Apply the scheme handlers.