Delete `module.go` Add `caddyfile.go` Update `go.mod` Update `go.sum` Add `tailscaleAuth.go`
28 lines
874 B
Go
28 lines
874 B
Go
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"
|
|
)
|
|
|
|
func init() {
|
|
httpcaddyfile.RegisterHandlerDirective("tailscale_auth", parseCaddyfile)
|
|
}
|
|
|
|
// 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
|
|
}
|