auth

package
v0.0.0-...-2e72ad6 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(load loadFunc, noCSRF ...string) func(http.Handler) http.Handler

Add user auth to an endpoint.

The load callback is called with the value of the authentication cookie. The User is added to the context.

POST, PATH, PUT, and DELETE requests will check the CSRF token from the "csrf" field with the value from User.CSRFToken(). The list of paths in noCSRF will be excluded for CSRF checks.

func ClearCookie

func ClearCookie(w http.ResponseWriter, domain string)

ClearCookie sends an empty auth cookie with an expiry in the past for the given domain, clearing it in the client.

Make sure the domain matches with what was sent before *exactly*, or the browser will set a second cookie.

func Filter

func Filter(f filterFunc) func(http.Handler) http.Handler

Filter access to a resource.

If the returning error is a zgo.at/guru.coder and has a redirect code, then the error value is used as a redirection.

func SetCookie

func SetCookie(w http.ResponseWriter, val, domain string)

SetCookie sets the authentication cookie to val for the given domain.

Types

type User

type User interface {
	CSRFToken() string
}

Jump to

Keyboard shortcuts

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