2015-01-03 12:03:57 -08:00
|
|
|
package authboss
|
|
|
|
|
2015-01-05 00:18:41 -08:00
|
|
|
import (
|
|
|
|
"io"
|
2015-01-23 16:25:12 -08:00
|
|
|
"time"
|
2015-02-08 23:08:33 -08:00
|
|
|
)
|
|
|
|
|
2015-01-05 00:18:41 -08:00
|
|
|
// Config holds all the configuration for both authboss and it's modules.
|
2015-01-04 10:33:53 -08:00
|
|
|
type Config struct {
|
2015-02-22 13:16:11 -08:00
|
|
|
// MountPath is the path to mount authboss's routes at (eg /auth).
|
2015-01-25 22:58:50 -08:00
|
|
|
MountPath string
|
2015-02-22 13:16:11 -08:00
|
|
|
// ViewsPath is the path to search for overridden templates.
|
2015-01-25 22:58:50 -08:00
|
|
|
ViewsPath string
|
2018-01-29 11:35:47 -08:00
|
|
|
// RootURL is the scheme+host+port of the web application (eg https://www.happiness.com:8080) for url generation. No trailing slash.
|
2015-03-12 19:20:15 -07:00
|
|
|
RootURL string
|
2015-02-22 13:16:11 -08:00
|
|
|
// BCryptCost is the cost of the bcrypt password hashing function.
|
2015-01-30 15:38:28 -08:00
|
|
|
BCryptCost int
|
2015-01-04 10:33:53 -08:00
|
|
|
|
2015-02-22 13:16:11 -08:00
|
|
|
// PrimaryID is the primary identifier of the user. Set to one of:
|
|
|
|
// authboss.StoreEmail, authboss.StoreUsername (StoreEmail is default)
|
|
|
|
PrimaryID string
|
|
|
|
|
2017-02-21 15:04:30 -08:00
|
|
|
// ViewLoader loads the templates for the application.
|
2017-02-20 15:56:26 -08:00
|
|
|
ViewLoader RenderLoader
|
2017-02-21 15:04:30 -08:00
|
|
|
// MailViewLoader loads the templates for mail. If this is nil, it will
|
|
|
|
// fall back to using the Renderer created from the ViewLoader instead.
|
|
|
|
MailViewLoader RenderLoader
|
2015-02-01 14:17:18 -08:00
|
|
|
|
2015-03-15 11:25:01 -07:00
|
|
|
// OAuth2Providers lists all providers that can be used. See
|
|
|
|
// OAuthProvider documentation for more details.
|
|
|
|
OAuth2Providers map[string]OAuth2Provider
|
2015-03-12 19:20:36 -07:00
|
|
|
|
2015-03-15 11:25:01 -07:00
|
|
|
// AuthLoginOKPath is the redirect path after a successful authentication.
|
|
|
|
AuthLoginOKPath string
|
|
|
|
// AuthLoginFailPath is the redirect path after a failed authentication.
|
2015-02-25 23:05:14 -08:00
|
|
|
AuthLoginFailPath string
|
2015-03-15 11:25:01 -07:00
|
|
|
// AuthLogoutOKPath is the redirect path after a log out.
|
|
|
|
AuthLogoutOKPath string
|
2015-01-04 10:33:53 -08:00
|
|
|
|
2015-03-15 11:25:01 -07:00
|
|
|
// RecoverOKPath is the redirect path after a successful recovery of a password.
|
|
|
|
RecoverOKPath string
|
|
|
|
// RecoverTokenDuration controls how long a token sent via email for password
|
|
|
|
// recovery is valid for.
|
2015-02-25 23:05:14 -08:00
|
|
|
RecoverTokenDuration time.Duration
|
2015-01-17 23:37:05 -08:00
|
|
|
|
2015-03-15 11:25:01 -07:00
|
|
|
// RegisterOKPath is the redirect path after a successful registration.
|
|
|
|
RegisterOKPath string
|
|
|
|
|
2015-03-15 08:31:48 -07:00
|
|
|
// Policies control validation of form fields and are automatically run
|
|
|
|
// against form posts that include the fields.
|
|
|
|
Policies []Validator
|
|
|
|
// ConfirmFields are fields that are supposed to be submitted with confirmation
|
|
|
|
// fields alongside them, passwords, emails etc.
|
2015-01-25 22:58:50 -08:00
|
|
|
ConfirmFields []string
|
2015-04-10 14:06:22 -07:00
|
|
|
// PreserveFields are fields used with registration that are to be rendered when
|
|
|
|
// post fails.
|
|
|
|
PreserveFields []string
|
2015-01-25 18:13:32 -08:00
|
|
|
|
2015-03-15 08:31:48 -07:00
|
|
|
// ExpireAfter controls the time an account is idle before being logged out
|
|
|
|
// by the ExpireMiddleware.
|
2015-02-22 13:16:11 -08:00
|
|
|
ExpireAfter time.Duration
|
|
|
|
|
2015-03-15 08:31:48 -07:00
|
|
|
// LockAfter this many tries.
|
|
|
|
LockAfter int
|
|
|
|
// LockWindow is the waiting time before the number of attemps are reset.
|
|
|
|
LockWindow time.Duration
|
|
|
|
// LockDuration is how long an account is locked for.
|
2015-01-25 22:58:50 -08:00
|
|
|
LockDuration time.Duration
|
2015-01-23 16:25:12 -08:00
|
|
|
|
2015-03-15 08:31:48 -07:00
|
|
|
// EmailFrom is the email address authboss e-mails come from.
|
|
|
|
EmailFrom string
|
|
|
|
// EmailSubjectPrefix is used to add something to the front of the authboss
|
|
|
|
// email subjects.
|
2015-01-25 22:58:50 -08:00
|
|
|
EmailSubjectPrefix string
|
2015-03-15 08:31:48 -07:00
|
|
|
|
2018-01-31 17:07:11 -08:00
|
|
|
// Storer is the interface through which Authboss accesses the web apps database
|
|
|
|
// for user operations.
|
|
|
|
Storer ServerStorer
|
2017-02-20 14:28:38 -08:00
|
|
|
|
2017-02-24 16:45:47 -08:00
|
|
|
// CookieStateStorer must be defined to provide an interface capapable of
|
|
|
|
// storing cookies for the given response, and reading them from the request.
|
|
|
|
CookieStateStorer ClientStateReadWriter
|
|
|
|
// SessionStateStorer must be defined to provide an interface capable of
|
|
|
|
// storing session-only values for the given response, and reading them
|
|
|
|
// from the request.
|
|
|
|
SessionStateStorer ClientStateReadWriter
|
|
|
|
// LogWriter is written to when errors occur, as well as on startup to show
|
|
|
|
// which modules are loaded and which routes they registered. By default
|
|
|
|
// writes to io.Discard.
|
2015-03-15 08:31:48 -07:00
|
|
|
LogWriter io.Writer
|
|
|
|
// Mailer is the mailer being used to send e-mails out. Authboss defines two loggers for use
|
|
|
|
// LogMailer and SMTPMailer, the default is a LogMailer to io.Discard.
|
|
|
|
Mailer Mailer
|
2015-01-05 00:18:41 -08:00
|
|
|
}
|
2015-01-04 10:33:53 -08:00
|
|
|
|
2015-03-31 12:34:03 -07:00
|
|
|
// Defaults sets the configuration's default values.
|
|
|
|
func (c *Config) Defaults() {
|
2018-01-29 13:14:55 -08:00
|
|
|
/*c.MountPath = "/"
|
2015-03-31 12:34:03 -07:00
|
|
|
c.ViewsPath = "./"
|
|
|
|
c.RootURL = "http://localhost:8080"
|
|
|
|
c.BCryptCost = bcrypt.DefaultCost
|
|
|
|
|
|
|
|
c.PrimaryID = StoreEmail
|
|
|
|
|
|
|
|
c.AuthLoginOKPath = "/"
|
|
|
|
c.AuthLoginFailPath = "/"
|
|
|
|
c.AuthLogoutOKPath = "/"
|
|
|
|
|
|
|
|
c.RecoverOKPath = "/"
|
|
|
|
c.RecoverTokenDuration = time.Duration(24) * time.Hour
|
|
|
|
|
|
|
|
c.RegisterOKPath = "/"
|
|
|
|
|
|
|
|
c.Policies = []Validator{
|
|
|
|
Rules{
|
2015-06-04 13:34:29 -07:00
|
|
|
FieldName: "email",
|
2015-03-31 12:34:03 -07:00
|
|
|
Required: true,
|
|
|
|
AllowWhitespace: false,
|
2015-01-30 15:38:28 -08:00
|
|
|
},
|
2015-03-31 12:34:03 -07:00
|
|
|
Rules{
|
|
|
|
FieldName: "password",
|
|
|
|
Required: true,
|
|
|
|
MinLength: 4,
|
|
|
|
MaxLength: 8,
|
|
|
|
AllowWhitespace: false,
|
2015-02-22 13:16:11 -08:00
|
|
|
},
|
2015-03-31 12:34:03 -07:00
|
|
|
}
|
|
|
|
c.ConfirmFields = []string{
|
|
|
|
StorePassword, ConfirmPrefix + StorePassword,
|
|
|
|
}
|
2015-01-30 15:38:28 -08:00
|
|
|
|
2015-03-31 12:34:03 -07:00
|
|
|
c.ExpireAfter = 60 * time.Minute
|
2015-02-26 23:09:37 -08:00
|
|
|
|
2015-03-31 12:34:03 -07:00
|
|
|
c.LockAfter = 3
|
|
|
|
c.LockWindow = 5 * time.Minute
|
|
|
|
c.LockDuration = 5 * time.Hour
|
2015-03-15 08:31:48 -07:00
|
|
|
|
2015-03-31 12:34:03 -07:00
|
|
|
c.LogWriter = NewDefaultLogger()
|
|
|
|
c.Mailer = LogMailer(ioutil.Discard)
|
2015-09-11 16:03:05 +02:00
|
|
|
c.ContextProvider = func(req *http.Request) context.Context {
|
|
|
|
return context.TODO()
|
2018-01-29 13:14:55 -08:00
|
|
|
}*/
|
2015-01-04 10:33:53 -08:00
|
|
|
}
|