auth

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: BSD-3-Clause-Clear Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const AuthCallbackPath = "/auth/callback"
View Source
const AuthCookieName = "fioserver-session"
View Source
const AuthLoginPath = "/auth/login"
View Source
const CsrfCookieName = "fioserver-csrf"
View Source
const CsrfHeaderName = "X-CSRF-Token"

Variables

This section is empty.

Functions

func CsrfCheck

func CsrfCheck(next echo.HandlerFunc) echo.HandlerFunc

CsrfCheck is a middleware that validates the CSRF token for non-safe HTTP methods (anything other than GET, HEAD, OPTIONS). It skips the check for requests that use an Authorization header (i.e. API token auth).

func NewRateLimiter

func NewRateLimiter(cfg storage.RateLimitConfig) *authRateLimiter

func PassCsrfCookie

func PassCsrfCookie(ctx context.Context, req *http.Request)

PassCsrfCookie transfer CSRF cookie from web request to API request. A CSRF token must be validated by the CsrfCheck middleware before this is possible.

func PasswordHash

func PasswordHash(password string) (string, error)

func PasswordVerify

func PasswordVerify(password, storedPassword string) (bool, error)

func RegisterProvider

func RegisterProvider(provider Provider)

func SetCsrfCookie

func SetCsrfCookie(c echo.Context, expires time.Time) string

SetCsrfCookie sets a CSRF cookie on the response. It should be called when a new session is created.

Types

type AuthUserFunc

type AuthUserFunc func(w http.ResponseWriter, r *http.Request) (User, error)

AuthUserFunc allows us to define a generic way for middleware to do authentication and authorization based on the incoming http request. The function returns nil if the user wasn't authenticated implying this function returned the proper error to the caller.

type PageContextBuilder

type PageContextBuilder interface {
	Base(c echo.Context, title, selected string) pagectx.Base
}

PageContextBuilder builds the shared base.html page context. It is implemented by the web layer and injected into providers so that provider login pages are rendered from the same single source as every other page.

type PasswordComplexityRules

type PasswordComplexityRules struct {
	RequireUppercase   bool
	RequireLowercase   bool
	RequireDigit       bool
	RequireSpecialChar string
}

type Provider

type Provider interface {
	Name() string

	// Configure can be used to:
	//  - set up routes on the Echo instance
	//  - initialize any provider-specific settings
	Configure(e *echo.Echo, users *users.Storage, authConfig *storage.AuthConfig, pageCtx PageContextBuilder) error

	// GetUser retrieves the user based on either an API token or session cookie.
	GetUser(c echo.Context) (*users.User, error)

	// GetSession retrieves the session associated with the given context.
	GetSession(c echo.Context) (*Session, error)
	DropSession(c echo.Context, session *Session)
}

Provider defines the interface that an authentication provider must implement to support a web server's authentication needs. This interface works for basic username/password authentication as well as OAuth2-based authentication.

func NewProvider

func NewProvider(e *echo.Echo, db *storage.DbHandle, fs *storage.FsHandle, users *users.Storage, pageCtx PageContextBuilder) (Provider, error)

type Session

type Session struct {
	BaseUrl string
	User    *users.User
	// Client is an HTTP client that includes the session cookie for making
	// authenticated requests against the REST api
	Client *http.Client
}

Session represents an authenticated web UI session.

type User

type User interface {
	Id() string
	Scopes() users.Scopes
}

Jump to

Keyboard shortcuts

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