formsauth

package module
v0.0.0-...-880095e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

README

caddy-formsauth

This is a Caddy module that implements simple form-based authentication.

  • Uses traditional sessions, with simple filesystem storage.
  • Configuration intended to resemble basicauth.
my-app.example

route {
  formsauth {
    # This path is captured to serve the login form.
    login_route /_login
    # Where to store session files.
    sessions_dir /var/lib/caddy/formsauth-sessions/my-app
    # A list of usernames and hashed passwords, like basicauth.
    users {
      stephank $2a$14$nA45/1wl4DoSUNi8ZbdAluk/OFTWqnnaJbMcH1PabrYLj.otmgsnK
    }
  }
  reverse_proxy 127.0.0.1:3000 {
    # Provide the username to the backend.
    header_up X-Remote-User "{http.auth.user.id}"
  }
}
Alternatives

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FormsAuth

type FormsAuth struct {
	// The path where the login form is served.
	LoginRoute string `json:"loginRoute"`

	// Directory where session files are stored.
	SessionsDir string `json:"sessionsDir"`

	// The algorithm with which the passwords are hashed. Default: bcrypt
	HashRaw json.RawMessage `json:"hash,omitempty" caddy:"namespace=http.authentication.hashes inline_key=algorithm"`

	// The list of accounts to authenticate.
	Accounts map[string]string `json:"accounts,omitempty"`
	// contains filtered or unexported fields
}

FormsAuth is the model for a formsauth directive.

func (*FormsAuth) CaddyModule

func (*FormsAuth) CaddyModule() caddy.ModuleInfo

func (*FormsAuth) Provision

func (fa *FormsAuth) Provision(ctx caddy.Context) error

func (*FormsAuth) ServeHTTP

func (fa *FormsAuth) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

type LoginContext

type LoginContext struct {
	LoginRoute string
	ReturnTo   string
}

LoginContext is the view-model for the login form template.

type Session

type Session struct {
	Id        string    `json:"id"`
	Username  string    `json:"username"`
	Refreshes time.Time `json:"refreshes"`
	Expires   time.Time `json:"expires"`
}

Session is the model for JSON session files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL