Documentation ¶
Overview ¶
Package defaults houses default implementations for the very many interfaces that authboss has. It's a goal of the defaults package to provide the core where authboss implements the shell.
It's simultaneously supposed to be possible to take as many or as few of these implementations as you desire, allowing you to reimplement where necessary, but reuse where possible.
Index ¶
- Constants
- func SetCore(config *authboss.Config, readJSON, useUsername bool)
- func URLValuesToMap(form url.Values) map[string]string
- type ConfirmValues
- type ErrorHandler
- type FieldError
- type HTTPBodyReader
- type HTTPFormValidator
- type JSONRenderer
- type LogMailer
- type Logger
- type RecoverEndValues
- type RecoverMiddleValues
- type RecoverStartValues
- type Redirector
- type Responder
- type Router
- type Rules
- type SMSTwoFA
- type SMTPMailer
- type TwoFA
- type UserValues
Constants ¶
const ( FormValueEmail = "email" FormValuePassword = "password" FormValueUsername = "username" FormValueConfirm = "cnf" FormValueToken = "token" FormValueCode = "code" FormValueRecoveryCode = "recovery_code" FormValuePhoneNumber = "phone_number" )
FormValue types
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConfirmValues ¶
type ConfirmValues struct { HTTPFormValidator Token string }
ConfirmValues retrieves values on the confirm page.
func (ConfirmValues) GetToken ¶
func (c ConfirmValues) GetToken() string
GetToken from the confirm values
type ErrorHandler ¶
ErrorHandler wraps http handlers with errors with itself to provide error handling.
The pieces provided to this struct must be thread-safe since they will be handed to many pointers to themselves.
func NewErrorHandler ¶
func NewErrorHandler(logger authboss.Logger) ErrorHandler
NewErrorHandler constructor
func (ErrorHandler) Wrap ¶
func (e ErrorHandler) Wrap(handler func(w http.ResponseWriter, r *http.Request) error) http.Handler
Wrap an http handler with an error
type FieldError ¶
FieldError represents an error that occurs during validation and is always attached to field on a form.
func NewFieldError ¶
func NewFieldError(name string, err error) FieldError
NewFieldError literally only exists because of poor name planning where name and err can't be exported on the struct due to the method names
type HTTPBodyReader ¶
type HTTPBodyReader struct { // ReadJSON if turned on reads json from the http request // instead of a encoded form. ReadJSON bool // UseUsername instead of e-mail address UseUsername bool // Rulesets for each page. Rulesets map[string][]Rules // Confirm fields for each page. Confirms map[string][]string // Whitelist values for each page through the html forms // this is for security so that we can properly protect the // arbitrary user API. In reality this really only needs to be set // for the register page since everything else is expecting // a hardcoded set of values. Whitelist map[string][]string }
HTTPBodyReader reads forms from various pages and decodes them.
func NewHTTPBodyReader ¶
func NewHTTPBodyReader(readJSON, useUsernameNotEmail bool) *HTTPBodyReader
NewHTTPBodyReader creates a form reader with default validation rules and fields for each page. If no defaults are required, simply construct this using the struct members itself for more control.
type HTTPFormValidator ¶
HTTPFormValidator validates HTTP post type inputs
func (HTTPFormValidator) Validate ¶
func (h HTTPFormValidator) Validate() []error
Validate validates a request using the given ruleset.
type JSONRenderer ¶
type JSONRenderer struct { }
JSONRenderer simply renders the data provided in JSON
func (JSONRenderer) Load ¶
func (JSONRenderer) Load(names ...string) error
Load is a no-op since json doesn't require any templates
type LogMailer ¶
LogMailer logs e-mails instead of sending them.
func NewLogMailer ¶
NewLogMailer creates a mailer that doesn't deliver e-mails but simply logs them.
type Logger ¶
Logger writes exactly once for each log line to underlying io.Writer that's passed in and ends each message with a newline. It has RFC3339 as a date format, and emits a log level.
type RecoverEndValues ¶
type RecoverEndValues struct { HTTPFormValidator Token string NewPassword string }
RecoverEndValues for recover_end page
func (RecoverEndValues) GetPassword ¶
func (r RecoverEndValues) GetPassword() string
GetPassword for recovery
func (RecoverEndValues) GetToken ¶
func (r RecoverEndValues) GetToken() string
GetToken for recovery
type RecoverMiddleValues ¶
type RecoverMiddleValues struct { HTTPFormValidator Token string }
RecoverMiddleValues for recover_middle page
func (RecoverMiddleValues) GetToken ¶
func (r RecoverMiddleValues) GetToken() string
GetToken for recovery
type RecoverStartValues ¶
type RecoverStartValues struct { HTTPFormValidator PID string }
RecoverStartValues for recover_start page
type Redirector ¶
type Redirector struct { Renderer authboss.Renderer // FormValueName for the redirection FormValueName string }
Redirector for http requests
func NewRedirector ¶
func NewRedirector(renderer authboss.Renderer, formValueName string) *Redirector
NewRedirector constructor
func (*Redirector) Redirect ¶
func (r *Redirector) Redirect(w http.ResponseWriter, req *http.Request, ro authboss.RedirectOptions) error
Redirect the client elsewhere. If it's an API request it will simply render a JSON response with information that should help a client to decide what to do.
type Responder ¶
Responder helps respond to http requests
func NewResponder ¶
NewResponder constructor
func (*Responder) Respond ¶
func (r *Responder) Respond(w http.ResponseWriter, req *http.Request, code int, page string, data authboss.HTMLData) error
Respond to an HTTP request. It's main job is to merge data that comes in from various middlewares via the context with the data sent by the controller and render that.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router implementation Does not use a dynamic map to hope to be slightly more performant
type Rules ¶
type Rules struct { // FieldName is the name of the field this is intended to validate. FieldName string // MatchError describes the MustMatch regexp to a user. Required bool MatchError string MustMatch *regexp.Regexp MinLength, MaxLength int MinLetters int MinLower, MinUpper int MinNumeric int MinSymbols int AllowWhitespace bool }
Rules defines a ruleset by which a string can be validated. The errors it produces are english only, with some basic pluralization.
func (Rules) Errors ¶
Errors returns an array of errors for each validation error that is present in the given string. Returns nil if there are no errors.
type SMSTwoFA ¶
type SMSTwoFA struct { HTTPFormValidator Code string RecoveryCode string PhoneNumber string }
SMSTwoFA for sms2fa_validate page
func (SMSTwoFA) GetPhoneNumber ¶
GetPhoneNumber from authenticator
func (SMSTwoFA) GetRecoveryCode ¶
GetRecoveryCode from sms
type SMTPMailer ¶
SMTPMailer uses smtp to actually send e-mails
func NewSMTPMailer ¶
func NewSMTPMailer(server string, auth smtp.Auth) *SMTPMailer
NewSMTPMailer creates an SMTP Mailer to send emails with. An example usage might be something like:
NewSMTPMailer("smtp.gmail.com", smtp.PlainAuth("", "admin@yoursite.com", "password", "smtp.gmail.com"))
type TwoFA ¶
type TwoFA struct { HTTPFormValidator Code string RecoveryCode string }
TwoFA for totp2fa_validate page
func (TwoFA) GetRecoveryCode ¶
GetRecoveryCode for authenticator
type UserValues ¶
type UserValues struct { HTTPFormValidator PID string Password string Arbitrary map[string]string }
UserValues from the login form
func (UserValues) GetPassword ¶
func (u UserValues) GetPassword() string
GetPassword from the values
func (UserValues) GetValues ¶
func (u UserValues) GetValues() map[string]string
GetValues from the form.