package caddy_tailscale import ( "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" "github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth" ) const directiveName = "tailscale_auth" func init() { httpcaddyfile.RegisterHandlerDirective(directiveName, parseCaddyfile) httpcaddyfile.RegisterDirectiveOrder(directiveName, httpcaddyfile.After, "basic_auth") } // parseCaddyfile sets up the handler from Caddyfile tokens. Syntax: // // tailscale_auth // // See also for further examples: https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/caddyauth/caddyfile.go func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) { h.Next() // consume directive name ta := new(TailscaleAuth) return caddyauth.Authentication{ ProvidersRaw: caddy.ModuleMap{ "tailscale": caddyconfig.JSON(ta, nil), }, }, nil }