Documentation
¶
Overview ¶
This is a tiny JSON database
Index ¶
- Constants
- Variables
- func AuthCookieGet(r *http.Request) string
- func AuthCookieGetWithName(r *http.Request, cookieName string) string
- func AuthCookieRemove(w http.ResponseWriter, r *http.Request, opts ...types.CookieOption)
- func AuthCookieSet(w http.ResponseWriter, r *http.Request, token string, ...)
- func AuthTokenRetrieve(r *http.Request, useCookies bool) string
- func AuthTokenRetrieveWithName(r *http.Request, useCookies bool, cookieName string) string
- func BearerTokenFromHeader(authHeader string) string
- func GeneratePasswordResetToken() (string, error)
- func GenerateVerificationCode(extraHardened bool) (string, error)
- func LoginCodeGamma(extraHardened bool) string
- func LoginCodeLength(extraHardened bool) int
- func ValidateEmailFormat(email string) string
- func ValidatePasswordStrength(password string, cfg *authtypes.PasswordStrengthConfig) error
- type Driver
- type InMemoryRateLimiter
- type Options
- type RateLimitResult
Constants ¶
const Version = "1.0.4"
Version is the current version of the project
Variables ¶
var ( ErrMissingResource = errors.New("missing resource - unable to save record") ErrMissingCollection = errors.New("missing collection - no place to save record") )
Functions ¶
func AuthCookieGet ¶ added in v0.30.0
func AuthCookieGetWithName ¶ added in v0.34.0
func AuthCookieRemove ¶ added in v0.30.0
func AuthCookieRemove(w http.ResponseWriter, r *http.Request, opts ...types.CookieOption)
func AuthCookieSet ¶ added in v0.30.0
func AuthCookieSet(w http.ResponseWriter, r *http.Request, token string, opts ...types.CookieOption)
func AuthTokenRetrieve ¶ added in v0.30.0
AuthTokenRetrieve retrieves the auth token from the request using the default cookie name. Several attempts are made:
- From cookie
- Authorization header (aka Bearer token)
- Request param "api_key"
- Request param "token"
func AuthTokenRetrieveWithName ¶ added in v0.34.0
AuthTokenRetrieveWithName retrieves the auth token from the request using the provided cookie name. If cookieName is empty, the default types.CookieName is used.
func BearerTokenFromHeader ¶ added in v0.29.0
BearerTokenFromHeader extracts the bearer token from the passed authorization header value. If a bearer token is not found, an empty string is returned.
Parameters:
- authHeader: a string representing the authorization header
Returns:
- a string representing the extracted bearer token
Example:
authHeader := r.Header.Get("Authorization")
authTokenFromBearerToken := BearerTokenFromHeader(authHeader)
or simplified
authTokenFromBearerToken := BearerTokenFromHeader(r.Header.Get("Authorization"))
func GeneratePasswordResetToken ¶ added in v0.29.0
GeneratePasswordResetToken generates a random password reset token.
func GenerateVerificationCode ¶ added in v0.29.0
GenerateVerificationCode generates a random verification code using the configured length and gamma.
func LoginCodeGamma ¶
LoginCodeGamma returns the character set (gamma) used for verification/ login codes. extraHardened should be false in normal operation; it is only set to true when rate limiting is explicitly disabled (again, not recommended for production). In that hardened mode it returns a much larger alphabet to drastically increase entropy; combined with the hardened length, this makes brute-force attacks negligible even without rate limiting.
func LoginCodeLength ¶
LoginCodeLength returns the length of verification/login codes. extraHardened should be false in normal operation; it is only set to true when rate limiting is explicitly disabled (which should never happen in production). In that hardened mode it returns a longer length to significantly increase the search space; together with the hardened gamma this yields an astronomically large space.
func ValidateEmailFormat ¶ added in v0.29.0
func ValidatePasswordStrength ¶ added in v0.29.0
func ValidatePasswordStrength(password string, cfg *authtypes.PasswordStrengthConfig) error
ValidatePasswordStrength validates the provided password against the supplied PasswordStrengthConfig. If cfg is nil, no checks are applied.
Types ¶
type Driver ¶ added in v0.30.0
type Driver struct {
// contains filtered or unexported fields
}
Driver is what is used to interact with the scribble database. It runs transactions, and provides log output
func New ¶ added in v0.30.0
New creates a new scribble database at the desired directory location, and returns a *Driver to then use for interacting with the database
func (*Driver) Delete ¶ added in v0.30.0
Delete locks the database then attempts to remove the collection/resource specified by path
type InMemoryRateLimiter ¶ added in v0.29.0
type InMemoryRateLimiter struct {
// contains filtered or unexported fields
}
InMemoryRateLimiter provides thread-safe in-memory rate limiting
func NewInMemoryRateLimiter ¶ added in v0.29.0
func NewInMemoryRateLimiter(maxAttempts int, windowDuration time.Duration, lockoutDuration time.Duration) *InMemoryRateLimiter
NewInMemoryRateLimiter creates a new in-memory rate limiter with default settings
func (*InMemoryRateLimiter) Check ¶ added in v0.29.0
func (r *InMemoryRateLimiter) Check(ip string, endpoint string) RateLimitResult
Check verifies if a request from the given IP to the given endpoint should be allowed
func (*InMemoryRateLimiter) Stop ¶ added in v0.29.0
func (r *InMemoryRateLimiter) Stop()
Stop gracefully stops the rate limiter's background cleanup
type RateLimitResult ¶ added in v0.29.0
RateLimitResult represents the result of a rate limit check