Documentation
¶
Index ¶
- Constants
- func CsrfCheck(next echo.HandlerFunc) echo.HandlerFunc
- func NewRateLimiter(cfg storage.RateLimitConfig) *authRateLimiter
- func PassCsrfCookie(ctx context.Context, req *http.Request)
- func PasswordHash(password string) (string, error)
- func PasswordVerify(password, storedPassword string) (bool, error)
- func RegisterProvider(provider Provider)
- func SetCsrfCookie(c echo.Context, expires time.Time) string
- type AuthUserFunc
- type PageContextBuilder
- type PasswordComplexityRules
- type Provider
- type Session
- type User
Constants ¶
const AuthCallbackPath = "/auth/callback"
const AuthCookieName = "fioserver-session"
const AuthLoginPath = "/auth/login"
const CsrfCookieName = "fioserver-csrf"
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 ¶
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 PasswordVerify ¶
func RegisterProvider ¶
func RegisterProvider(provider Provider)
Types ¶
type AuthUserFunc ¶
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 ¶
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 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.