2015-01-03 22:03:57 +02:00
|
|
|
package authboss
|
|
|
|
|
2015-01-05 10:18:41 +02:00
|
|
|
import (
|
2015-01-24 02:25:12 +02:00
|
|
|
"time"
|
2018-02-05 09:28:31 +02:00
|
|
|
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
2015-02-09 09:08:33 +02:00
|
|
|
)
|
|
|
|
|
2015-01-05 10:18:41 +02:00
|
|
|
// Config holds all the configuration for both authboss and it's modules.
|
2015-01-04 20:33:53 +02:00
|
|
|
type Config struct {
|
2018-02-02 01:42:48 +02:00
|
|
|
Paths struct {
|
|
|
|
// Mount is the path to mount authboss's routes at (eg /auth).
|
|
|
|
Mount string
|
|
|
|
|
|
|
|
// AuthLoginOK is the redirect path after a successful authentication.
|
|
|
|
AuthLoginOK string
|
|
|
|
// AuthLogoutOK is the redirect path after a log out.
|
|
|
|
AuthLogoutOK string
|
|
|
|
|
2018-02-27 17:14:30 +02:00
|
|
|
// ConfirmOK once a user has confirmed their account, where should they go
|
|
|
|
ConfirmOK string
|
|
|
|
// ConfirmNotOK is used by the middleware, when a user is still supposed to
|
|
|
|
// confirm their account, this is where they should be redirected to.
|
|
|
|
ConfirmNotOK string
|
|
|
|
|
2018-02-28 07:20:55 +02:00
|
|
|
// LockNotOK is a path to go to when the user fails
|
|
|
|
LockNotOK string
|
|
|
|
|
2018-02-02 01:42:48 +02:00
|
|
|
// RecoverOK is the redirect path after a successful recovery of a password.
|
|
|
|
RecoverOK string
|
|
|
|
|
|
|
|
// RegisterOK is the redirect path after a successful registration.
|
|
|
|
RegisterOK string
|
|
|
|
|
|
|
|
// RootURL is the scheme+host+port of the web application (eg https://www.happiness.com:8080) for url generation. No trailing slash.
|
|
|
|
RootURL string
|
|
|
|
}
|
|
|
|
|
|
|
|
Modules struct {
|
2018-03-06 03:47:11 +02:00
|
|
|
// BCryptCost is the cost of the bcrypt password hashing function.
|
|
|
|
BCryptCost int
|
|
|
|
|
2018-02-05 09:28:31 +02:00
|
|
|
// AuthLogoutMethod is the method the logout route should use (default should be DELETE)
|
|
|
|
AuthLogoutMethod string
|
2018-02-02 01:42:48 +02:00
|
|
|
|
|
|
|
// ExpireAfter controls the time an account is idle before being logged out
|
|
|
|
// by the ExpireMiddleware.
|
|
|
|
ExpireAfter time.Duration
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
LockDuration time.Duration
|
2018-02-05 09:28:31 +02:00
|
|
|
|
|
|
|
// RegisterPreserveFields are fields used with registration that are to be rendered when
|
2018-02-26 01:20:57 +02:00
|
|
|
// post fails in a normal way (for example validation errors), they will be passed
|
|
|
|
// back in the data of the response under the key DataPreserve which will be a map[string]string.
|
|
|
|
//
|
|
|
|
// All fields that are to be preserved must be able to be returned by the ArbitraryValuer.GetValues()
|
|
|
|
//
|
|
|
|
// This means in order to have a field named "address" you would need to have that returned by
|
|
|
|
// the ArbitraryValuer.GetValues() method and then it would be available to be whitelisted by this
|
|
|
|
// configuration variable.
|
2018-02-05 09:28:31 +02:00
|
|
|
RegisterPreserveFields []string
|
|
|
|
|
|
|
|
// RecoverTokenDuration controls how long a token sent via email for password
|
|
|
|
// recovery is valid for.
|
|
|
|
RecoverTokenDuration time.Duration
|
2018-03-06 03:47:11 +02:00
|
|
|
// RecoverLoginAfterRecovery says for the recovery module after a user has successfully
|
|
|
|
// recovered the password, are they simply logged in, or are they redirected to
|
|
|
|
// the login page with an "updated password" message.
|
|
|
|
RecoverLoginAfterRecovery bool
|
2018-02-05 09:28:31 +02:00
|
|
|
|
|
|
|
// OAuth2Providers lists all providers that can be used. See
|
|
|
|
// OAuthProvider documentation for more details.
|
|
|
|
OAuth2Providers map[string]OAuth2Provider
|
2018-02-02 01:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Mail struct {
|
|
|
|
// From is the email address authboss e-mails come from.
|
|
|
|
From string
|
|
|
|
// SubjectPrefix is used to add something to the front of the authboss
|
|
|
|
// email subjects.
|
|
|
|
SubjectPrefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
Storage struct {
|
|
|
|
// Storer is the interface through which Authboss accesses the web apps database
|
|
|
|
// for user operations.
|
|
|
|
Server ServerStorer
|
|
|
|
|
|
|
|
// CookieState must be defined to provide an interface capapable of
|
|
|
|
// storing cookies for the given response, and reading them from the request.
|
|
|
|
CookieState ClientStateReadWriter
|
|
|
|
// SessionState must be defined to provide an interface capable of
|
|
|
|
// storing session-only values for the given response, and reading them
|
|
|
|
// from the request.
|
|
|
|
SessionState ClientStateReadWriter
|
|
|
|
}
|
|
|
|
|
|
|
|
Core struct {
|
|
|
|
// Router is the entity that controls all routing to authboss routes
|
|
|
|
// modules will register their routes with it.
|
|
|
|
Router Router
|
|
|
|
|
2018-02-03 01:41:24 +02:00
|
|
|
// ErrorHandler wraps http requests with centralized error handling.
|
|
|
|
ErrorHandler ErrorHandler
|
|
|
|
|
2018-02-02 01:42:48 +02:00
|
|
|
// Responder takes a generic response from a controller and prepares
|
|
|
|
// the response, uses a renderer to create the body, and replies to the
|
|
|
|
// http request.
|
|
|
|
Responder HTTPResponder
|
|
|
|
|
|
|
|
// Redirector can redirect a response, similar to Responder but responsible
|
|
|
|
// only for redirection.
|
|
|
|
Redirector HTTPRedirector
|
|
|
|
|
2018-02-05 07:24:55 +02:00
|
|
|
// BodyReader reads validatable data from the body of a request to be able
|
|
|
|
// to get data from the user's client.
|
|
|
|
BodyReader BodyReader
|
2018-02-02 01:42:48 +02:00
|
|
|
|
|
|
|
// ViewRenderer loads the templates for the application.
|
|
|
|
ViewRenderer Renderer
|
|
|
|
// MailRenderer loads the templates for mail. If this is nil, it will
|
|
|
|
// fall back to using the Renderer created from the ViewLoader instead.
|
|
|
|
MailRenderer Renderer
|
|
|
|
|
|
|
|
// Mailer is the mailer being used to send e-mails out via smtp
|
|
|
|
Mailer Mailer
|
|
|
|
|
2018-02-02 22:11:47 +02:00
|
|
|
// Logger implies just a few log levels for use, can optionally
|
|
|
|
// also implement the ContextLogger to be able to upgrade to a
|
|
|
|
// request specific logger.
|
|
|
|
Logger Logger
|
2018-02-02 01:42:48 +02:00
|
|
|
}
|
2015-01-05 10:18:41 +02:00
|
|
|
}
|
2015-01-04 20:33:53 +02:00
|
|
|
|
2015-03-31 21:34:03 +02:00
|
|
|
// Defaults sets the configuration's default values.
|
|
|
|
func (c *Config) Defaults() {
|
2018-03-06 03:47:11 +02:00
|
|
|
c.Paths.Mount = "/auth"
|
2018-02-05 09:28:31 +02:00
|
|
|
c.Paths.RootURL = "http://localhost:8080"
|
|
|
|
c.Paths.AuthLoginOK = "/"
|
|
|
|
c.Paths.AuthLogoutOK = "/"
|
2018-03-06 03:47:11 +02:00
|
|
|
c.Paths.ConfirmOK = "/"
|
|
|
|
c.Paths.ConfirmNotOK = "/"
|
2018-02-05 09:28:31 +02:00
|
|
|
c.Paths.RecoverOK = "/"
|
|
|
|
c.Paths.RegisterOK = "/"
|
|
|
|
|
2018-03-06 03:47:11 +02:00
|
|
|
c.Modules.BCryptCost = bcrypt.DefaultCost
|
2018-02-05 09:28:31 +02:00
|
|
|
c.Modules.AuthLogoutMethod = "DELETE"
|
|
|
|
c.Modules.ExpireAfter = 60 * time.Minute
|
|
|
|
c.Modules.LockAfter = 3
|
|
|
|
c.Modules.LockWindow = 5 * time.Minute
|
|
|
|
c.Modules.LockDuration = 5 * time.Hour
|
|
|
|
c.Modules.RecoverTokenDuration = time.Duration(24) * time.Hour
|
2015-01-04 20:33:53 +02:00
|
|
|
}
|