Versions in this module Expand all Collapse all v3 v3.0.0 Jan 13, 2024 Changes in this version + const CTXKeyCookieState + const CTXKeyData + const CTXKeyPID + const CTXKeySessionState + const CTXKeyUser + const CTXKeyValues + const ConfirmPrefix + const CookieRemember + const DataErr + const DataModules + const DataPreserve + const DataValidation + const FlashErrorKey + const FlashSuccessKey + const FormValueRedirect + const Session2FA + const Session2FAAuthToken + const Session2FAAuthed + const SessionHalfAuthKey + const SessionKey + const SessionLastAction + const SessionOAuth2Params + const SessionOAuth2State + var ErrTokenNotFound = errors.New("token not found") + var ErrUserFound = errors.New("user found") + var ErrUserNotFound = errors.New("user not found") + var Txt2FAAuthorizationRequired = LocalizationKey + var TxtAccountNotConfirmed = LocalizationKey + var TxtAuthFailed = LocalizationKey + var TxtConfirmEmailSubject = LocalizationKey + var TxtConfirmYourAccount = LocalizationKey + var TxtConfrimationSuccess = LocalizationKey + var TxtEmailVerifySubject = LocalizationKey + var TxtEmailVerifyTriggered = LocalizationKey + var TxtInvalid2FACode = LocalizationKey + var TxtInvalid2FAVerificationToken = LocalizationKey + var TxtInvalidConfirmToken = LocalizationKey + var TxtInvalidCredentials = LocalizationKey + var TxtLocked = LocalizationKey + var TxtLoggedOut = LocalizationKey + var TxtOAuth2LoginNotOK = LocalizationKey + var TxtOAuth2LoginOK = LocalizationKey + var TxtPasswordResetEmailSubject = LocalizationKey + var TxtRecoverAndLoginSuccessMsg = LocalizationKey + var TxtRecoverInitiateSuccessFlash = LocalizationKey + var TxtRecoverSuccessMsg = LocalizationKey + var TxtRegisteredAndLoggedIn = LocalizationKey + var TxtRepeated2FACode = LocalizationKey + var TxtSMSNumberRequired = LocalizationKey + var TxtSMSWaitToResend = LocalizationKey + var TxtSuccess = LocalizationKey + var TxtTOTP2FANotActive = LocalizationKey + var TxtTooManyOTPs = LocalizationKey + var TxtUserAlreadyExists = LocalizationKey + func DelAllSession(w http.ResponseWriter, whitelist []string) + func DelCookie(w http.ResponseWriter, key string) + func DelKnownCookie(w http.ResponseWriter) + func DelKnownSession(w http.ResponseWriter) + func DelSession(w http.ResponseWriter, key string) + func ErrorMap(e []error) map[string][]string + func FlashError(w http.ResponseWriter, r *http.Request) string + func FlashSuccess(w http.ResponseWriter, r *http.Request) string + func GetCookie(r *http.Request, key string) (string, bool) + func GetSession(r *http.Request, key string) (string, bool) + func IsFullyAuthed(r *http.Request) bool + func IsTwoFactored(r *http.Request) bool + func MakeOAuth2PID(provider, uid string) string + func MergeDataInRequest(r **http.Request, other HTMLData) + func Middleware(ab *Authboss, redirectToLogin bool, forceFullAuth bool, force2fa bool) func(http.Handler) http.Handler + func Middleware2(ab *Authboss, requirements MWRequirements, failureResponse MWRespondOnFailure) func(http.Handler) http.Handler + func ModuleListMiddleware(ab *Authboss) func(http.Handler) http.Handler + func MountedMiddleware(ab *Authboss, mountPathed, redirectToLogin, forceFullAuth, force2fa bool) func(http.Handler) http.Handler + func MountedMiddleware2(ab *Authboss, mountPathed bool, reqs MWRequirements, ...) func(http.Handler) http.Handler + func NewBCryptHasher(cost int) *bcryptHasher + func ParseOAuth2PID(pid string) (provider, uid string, err error) + func ParseOAuth2PIDP(pid string) (provider, uid string) + func PutCookie(w http.ResponseWriter, key, val string) + func PutSession(w http.ResponseWriter, key, val string) + func RegisterModule(name string, m Moduler) + func RegisteredModules() []string + func VerifyPassword(user AuthableUser, password string) error + type ArbitraryUser interface + GetArbitrary func() (arbitrary map[string]string) + PutArbitrary func(arbitrary map[string]string) + type ArbitraryValuer interface + GetValues func() map[string]string + type AuthableUser interface + GetPassword func() (password string) + PutPassword func(password string) + func MustBeAuthable(u User) AuthableUser + type Authboss struct + Events *Events + func New() *Authboss + func (a *Authboss) CurrentUser(r *http.Request) (User, error) + func (a *Authboss) CurrentUserID(r *http.Request) (string, error) + func (a *Authboss) CurrentUserIDP(r *http.Request) string + func (a *Authboss) CurrentUserP(r *http.Request) User + func (a *Authboss) Email(ctx context.Context, email Email, ro EmailResponseOptions) error + func (a *Authboss) Init(modulesToLoad ...string) error + func (a *Authboss) IsLoaded(mod string) bool + func (a *Authboss) LoadClientState(w http.ResponseWriter, r *http.Request) (*http.Request, error) + func (a *Authboss) LoadClientStateMiddleware(h http.Handler) http.Handler + func (a *Authboss) LoadCurrentUser(r **http.Request) (User, error) + func (a *Authboss) LoadCurrentUserID(r **http.Request) (string, error) + func (a *Authboss) LoadCurrentUserIDP(r **http.Request) string + func (a *Authboss) LoadCurrentUserP(r **http.Request) User + func (a *Authboss) LoadedModules() []string + func (a *Authboss) Localizef(ctx context.Context, key LocalizationKey, args ...any) string + func (a *Authboss) Logger(ctx context.Context) FmtLogger + func (a *Authboss) NewResponse(w http.ResponseWriter) *ClientStateResponseWriter + func (a *Authboss) RequestLogger(r *http.Request) FmtLogger + func (a *Authboss) UpdatePassword(ctx context.Context, user AuthableUser, newPassword string) error + func (a *Authboss) VerifyPassword(user AuthableUser, password string) error + type BodyReader interface + Read func(page string, r *http.Request) (Validator, error) + type ClientState interface + Get func(key string) (string, bool) + type ClientStateEvent struct + Key string + Kind ClientStateEventKind + Value string + type ClientStateEventKind int + const ClientStateEventDel + const ClientStateEventDelAll + const ClientStateEventPut + type ClientStateReadWriter interface + ReadState func(*http.Request) (ClientState, error) + WriteState func(http.ResponseWriter, ClientState, []ClientStateEvent) error + type ClientStateResponseWriter struct + func MustClientStateResponseWriter(w http.ResponseWriter) *ClientStateResponseWriter + func (c *ClientStateResponseWriter) UnderlyingResponseWriter() http.ResponseWriter + func (c *ClientStateResponseWriter) Unwrap() http.ResponseWriter + func (c *ClientStateResponseWriter) Write(b []byte) (int, error) + func (c *ClientStateResponseWriter) WriteHeader(code int) + func (c ClientStateResponseWriter) Header() http.Header + func (c ClientStateResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) + type Config struct + Core struct{ ... } + Mail struct{ ... } + Modules struct{ ... } + Paths struct{ ... } + Storage struct{ ... } + func (c *Config) Defaults() + type ConfirmValuer interface + GetToken func() string + func MustHaveConfirmValues(v Validator) ConfirmValuer + type ConfirmableUser interface + GetConfirmSelector func() (selector string) + GetConfirmVerifier func() (verifier string) + GetConfirmed func() (confirmed bool) + GetEmail func() (email string) + PutConfirmSelector func(selector string) + PutConfirmVerifier func(verifier string) + PutConfirmed func(confirmed bool) + PutEmail func(email string) + func MustBeConfirmable(u User) ConfirmableUser + type ConfirmingServerStorer interface + LoadByConfirmSelector func(ctx context.Context, selector string) (ConfirmableUser, error) + func EnsureCanConfirm(storer ServerStorer) ConfirmingServerStorer + type ContextLogger interface + FromContext func(context.Context) Logger + type CreatingServerStorer interface + Create func(ctx context.Context, user User) error + New func(ctx context.Context) User + func EnsureCanCreate(storer ServerStorer) CreatingServerStorer + type Email struct + Bcc []string + BccNames []string + Cc []string + CcNames []string + From string + FromName string + HTMLBody string + ReplyTo string + ReplyToName string + Subject string + TextBody string + To []string + ToNames []string + type EmailResponseOptions struct + Data HTMLData + HTMLTemplate string + TextTemplate string + type ErrorHandler interface + Wrap func(func(w http.ResponseWriter, r *http.Request) error) http.Handler + type ErrorList []error + func (e ErrorList) Error() string + func (e ErrorList) Map() map[string][]string + type Event int + const EventAuth + const EventAuthFail + const EventAuthHijack + const EventGetUser + const EventGetUserSession + const EventLogout + const EventOAuth2 + const EventOAuth2Fail + const EventPasswordReset + const EventRecoverEnd + const EventRecoverStart + const EventRegister + const EventTwoFactorAdded + const EventTwoFactorRemoved + func (i Event) String() string + type EventHandler func(w http.ResponseWriter, r *http.Request, handled bool) (bool, error) + type Events struct + func NewEvents() *Events + func (c *Events) After(e Event, f EventHandler) + func (c *Events) Before(e Event, f EventHandler) + func (c *Events) FireAfter(e Event, w http.ResponseWriter, r *http.Request) (bool, error) + func (c *Events) FireBefore(e Event, w http.ResponseWriter, r *http.Request) (bool, error) + type FieldError interface + Err func() error + Name func() string + type FmtLogger struct + func (f FmtLogger) Errorf(format string, values ...interface{}) + func (f FmtLogger) Infof(format string, values ...interface{}) + type HTMLData map[string]interface + func (h HTMLData) Merge(other HTMLData) HTMLData + func (h HTMLData) MergeKV(data ...interface{}) HTMLData + func NewHTMLData(data ...interface{}) HTMLData + type HTTPRedirector interface + Redirect func(w http.ResponseWriter, r *http.Request, ro RedirectOptions) error + type HTTPResponder interface + Respond func(w http.ResponseWriter, r *http.Request, code int, templateName string, ...) error + type Hasher interface + CompareHashAndPassword func(hash, password string) error + GenerateHash func(password string) (string, error) + type LocalizationKey struct + Default string + ID string + type Localizer interface + Localizef func(ctx context.Context, key LocalizationKey, args ...any) string + type LockableUser interface + GetAttemptCount func() (attempts int) + GetLastAttempt func() (last time.Time) + GetLocked func() (locked time.Time) + PutAttemptCount func(attempts int) + PutLastAttempt func(last time.Time) + PutLocked func(locked time.Time) + func MustBeLockable(u User) LockableUser + type Logger interface + Error func(string) + Info func(string) + type MWRequirements int + const Require2FA + const RequireFullAuth + const RequireNone + type MWRespondOnFailure int + const RespondNotFound + const RespondRedirect + const RespondUnauthorized + type Mailer interface + Send func(context.Context, Email) error + type Moduler interface + Init func(*Authboss) error + type OAuth2Provider struct + AdditionalParams url.Values + FindUserDetails func(context.Context, oauth2.Config, *oauth2.Token) (map[string]string, error) + OAuth2Config *oauth2.Config + type OAuth2ServerStorer interface + NewFromOAuth2 func(ctx context.Context, provider string, details map[string]string) (OAuth2User, error) + SaveOAuth2 func(ctx context.Context, user OAuth2User) error + func EnsureCanOAuth2(storer ServerStorer) OAuth2ServerStorer + type OAuth2User interface + GetOAuth2AccessToken func() (token string) + GetOAuth2Expiry func() (expiry time.Time) + GetOAuth2Provider func() (provider string) + GetOAuth2RefreshToken func() (refreshToken string) + GetOAuth2UID func() (uid string) + IsOAuth2User func() bool + PutOAuth2AccessToken func(token string) + PutOAuth2Expiry func(expiry time.Time) + PutOAuth2Provider func(provider string) + PutOAuth2RefreshToken func(refreshToken string) + PutOAuth2UID func(uid string) + func MustBeOAuthable(u User) OAuth2User + type OneTimeTokenGenerator interface + GenerateToken func() (selector, verifier, token string, err error) + ParseToken func(token string) (selectorBytes, verifierBytes []byte) + TokenSize func() int + type RecoverEndValuer interface + GetPassword func() string + GetToken func() string + func MustHaveRecoverEndValues(v Validator) RecoverEndValuer + type RecoverMiddleValuer interface + GetToken func() string + func MustHaveRecoverMiddleValues(v Validator) RecoverMiddleValuer + type RecoverStartValuer interface + GetPID func() string + func MustHaveRecoverStartValues(v Validator) RecoverStartValuer + type RecoverableUser interface + GetEmail func() (email string) + GetRecoverExpiry func() (expiry time.Time) + GetRecoverSelector func() (selector string) + GetRecoverVerifier func() (verifier string) + PutEmail func(email string) + PutRecoverExpiry func(expiry time.Time) + PutRecoverSelector func(selector string) + PutRecoverVerifier func(verifier string) + func MustBeRecoverable(u User) RecoverableUser + type RecoverableUserWithSecondaryEmails interface + GetSecondaryEmails func() (secondaryEmails []string) + func CanBeRecoverableUserWithSecondaryEmails(u User) (RecoverableUserWithSecondaryEmails, bool) + type RecoveringServerStorer interface + LoadByRecoverSelector func(ctx context.Context, selector string) (RecoverableUser, error) + func EnsureCanRecover(storer ServerStorer) RecoveringServerStorer + type RedirectOptions struct + Code int + Failure string + FollowRedirParam bool + RedirectPath string + Success string + type RememberValuer interface + GetShouldRemember func() bool + type RememberingServerStorer interface + AddRememberToken func(ctx context.Context, pid, token string) error + DelRememberTokens func(ctx context.Context, pid string) error + UseRememberToken func(ctx context.Context, pid, token string) error + func EnsureCanRemember(storer ServerStorer) RememberingServerStorer + type Renderer interface + Load func(names ...string) error + Render func(ctx context.Context, page string, data HTMLData) (output []byte, contentType string, err error) + type RequestLogger interface + FromRequest func(*http.Request) Logger + type Router interface + Delete func(path string, handler http.Handler) + Get func(path string, handler http.Handler) + Post func(path string, handler http.Handler) + type ServerStorer interface + Load func(ctx context.Context, key string) (User, error) + Save func(ctx context.Context, user User) error + type Sha512TokenGenerator struct + func NewSha512TokenGenerator() *Sha512TokenGenerator + func (cg *Sha512TokenGenerator) GenerateToken() (selector, verifier, token string, err error) + func (cg *Sha512TokenGenerator) ParseToken(rawToken string) (selectorBytes, verifierBytes []byte) + func (cg *Sha512TokenGenerator) TokenSize() int + type UnderlyingResponseWriter interface + UnderlyingResponseWriter func() http.ResponseWriter + type User interface + GetPID func() (pid string) + PutPID func(pid string) + type UserValuer interface + GetPID func() string + GetPassword func() string + func MustHaveUserValues(v Validator) UserValuer + type Validator interface + Validate func() []error + type WrappingResponseWriter interface + Unwrap func() http.ResponseWriter