mirror of
https://github.com/volatiletech/authboss.git
synced 2025-09-16 09:06:20 +02:00
no DisableGoroutines (just check for -Maker); no ModuleNames; test fix
This commit is contained in:
@@ -12,8 +12,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModuleName = "auth"
|
|
||||||
|
|
||||||
methodGET = "GET"
|
methodGET = "GET"
|
||||||
methodPOST = "POST"
|
methodPOST = "POST"
|
||||||
|
|
||||||
@@ -21,7 +19,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
authboss.RegisterModule(ModuleName, &Auth{})
|
authboss.RegisterModule("auth", &Auth{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auth module
|
// Auth module
|
||||||
|
18
config.go
18
config.go
@@ -21,8 +21,6 @@ type Config struct {
|
|||||||
RootURL string
|
RootURL string
|
||||||
// BCryptCost is the cost of the bcrypt password hashing function.
|
// BCryptCost is the cost of the bcrypt password hashing function.
|
||||||
BCryptCost int
|
BCryptCost int
|
||||||
// If true, authboss won't use any goroutines. Dependencies of authboss may or may not use goroutines.
|
|
||||||
DisableGoroutines bool
|
|
||||||
|
|
||||||
// PrimaryID is the primary identifier of the user. Set to one of:
|
// PrimaryID is the primary identifier of the user. Set to one of:
|
||||||
// authboss.StoreEmail, authboss.StoreUsername (StoreEmail is default)
|
// authboss.StoreEmail, authboss.StoreUsername (StoreEmail is default)
|
||||||
@@ -106,7 +104,9 @@ type Config struct {
|
|||||||
// a Storer on demand from the current http request. Unless you have an exceedingly unusual
|
// a Storer on demand from the current http request. Unless you have an exceedingly unusual
|
||||||
// special requirement, defining Storer directly is the preferred pattern; literally the only
|
// special requirement, defining Storer directly is the preferred pattern; literally the only
|
||||||
// known use case at the time of this property being added is Google App Engine, which requires
|
// known use case at the time of this property being added is Google App Engine, which requires
|
||||||
// the current context as an argument to its datastore API methods.
|
// the current context as an argument to its datastore API methods. To avoid passing StoreMaker
|
||||||
|
// an expired request object, where relevant, calls to this function will never be spun off as
|
||||||
|
// goroutines.
|
||||||
StoreMaker StoreMaker
|
StoreMaker StoreMaker
|
||||||
// OAuth2Storer is a different kind of storer only meant for OAuth2.
|
// OAuth2Storer is a different kind of storer only meant for OAuth2.
|
||||||
OAuth2Storer OAuth2Storer
|
OAuth2Storer OAuth2Storer
|
||||||
@@ -114,7 +114,9 @@ type Config struct {
|
|||||||
// a OAuth2Storer on demand from the current http request. Unless you have an exceedingly unusual
|
// a OAuth2Storer on demand from the current http request. Unless you have an exceedingly unusual
|
||||||
// special requirement, defining OAuth2Storer directly is the preferred pattern; literally the only
|
// special requirement, defining OAuth2Storer directly is the preferred pattern; literally the only
|
||||||
// known use case at the time of this property being added is Google App Engine, which requires
|
// known use case at the time of this property being added is Google App Engine, which requires
|
||||||
// the current context as an argument to its datastore API methods.
|
// the current context as an argument to its datastore API methods. To avoid passing OAuth2StoreMaker
|
||||||
|
// an expired request object, where relevant, calls to this function will never be spun off as
|
||||||
|
// goroutines.
|
||||||
OAuth2StoreMaker OAuth2StoreMaker
|
OAuth2StoreMaker OAuth2StoreMaker
|
||||||
// CookieStoreMaker must be defined to provide an interface capapable of storing cookies
|
// CookieStoreMaker must be defined to provide an interface capapable of storing cookies
|
||||||
// for the given response, and reading them from the request.
|
// for the given response, and reading them from the request.
|
||||||
@@ -129,7 +131,9 @@ type Config struct {
|
|||||||
// a LogWriter on demand from the current http request. Unless you have an exceedingly unusual
|
// a LogWriter on demand from the current http request. Unless you have an exceedingly unusual
|
||||||
// special requirement, defining LogWriter directly is the preferred pattern; literally the only
|
// special requirement, defining LogWriter directly is the preferred pattern; literally the only
|
||||||
// known use case at the time of this property being added is Google App Engine, which requires
|
// known use case at the time of this property being added is Google App Engine, which requires
|
||||||
// the current context as an argument to its logging API methods.
|
// the current context as an argument to its logging API methods. To avoid passing LogWriteMaker
|
||||||
|
// an expired request object, where relevant, calls to this function will never be spun off as
|
||||||
|
// goroutines.
|
||||||
LogWriteMaker LogWriteMaker
|
LogWriteMaker LogWriteMaker
|
||||||
// Mailer is the mailer being used to send e-mails out. Authboss defines two loggers for use
|
// 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.
|
// LogMailer and SMTPMailer, the default is a LogMailer to io.Discard.
|
||||||
@@ -138,7 +142,9 @@ type Config struct {
|
|||||||
// a Mailer on demand from the current http request. Unless you have an exceedingly unusual
|
// a Mailer on demand from the current http request. Unless you have an exceedingly unusual
|
||||||
// special requirement, defining Mailer directly is the preferred pattern; literally the only
|
// special requirement, defining Mailer directly is the preferred pattern; literally the only
|
||||||
// known use case at the time of this property being added is Google App Engine, which requires
|
// known use case at the time of this property being added is Google App Engine, which requires
|
||||||
// the current context as an argument to its mail API methods.
|
// the current context as an argument to its mail API methods. To avoid passing MailMaker
|
||||||
|
// an expired request object, where relevant, calls to this function will never be spun off as
|
||||||
|
// goroutines.
|
||||||
MailMaker MailMaker
|
MailMaker MailMaker
|
||||||
// ContextProvider provides a context for a given request
|
// ContextProvider provides a context for a given request
|
||||||
ContextProvider func(*http.Request) context.Context
|
ContextProvider func(*http.Request) context.Context
|
||||||
|
@@ -17,8 +17,6 @@ import (
|
|||||||
|
|
||||||
// Storer and FormValue constants
|
// Storer and FormValue constants
|
||||||
const (
|
const (
|
||||||
ModuleName = "confirm"
|
|
||||||
|
|
||||||
StoreConfirmToken = "confirm_token"
|
StoreConfirmToken = "confirm_token"
|
||||||
StoreConfirmed = "confirmed"
|
StoreConfirmed = "confirmed"
|
||||||
|
|
||||||
@@ -43,7 +41,7 @@ type ConfirmStorer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
authboss.RegisterModule(ModuleName, &Confirm{})
|
authboss.RegisterModule("confirm", &Confirm{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirm module
|
// Confirm module
|
||||||
@@ -138,7 +136,7 @@ func (c *Confirm) afterRegister(ctx *authboss.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var goConfirmEmail = func(c *Confirm, ctx *authboss.Context, to, token string) {
|
var goConfirmEmail = func(c *Confirm, ctx *authboss.Context, to, token string) {
|
||||||
if ctx.DisableGoroutines {
|
if ctx.MailMaker != nil {
|
||||||
c.confirmEmail(ctx, to, token)
|
c.confirmEmail(ctx, to, token)
|
||||||
} else {
|
} else {
|
||||||
go c.confirmEmail(ctx, to, token)
|
go c.confirmEmail(ctx, to, token)
|
||||||
|
@@ -10,8 +10,6 @@ import (
|
|||||||
|
|
||||||
// Storage key constants
|
// Storage key constants
|
||||||
const (
|
const (
|
||||||
ModuleName = "Lock"
|
|
||||||
|
|
||||||
StoreAttemptNumber = "attempt_number"
|
StoreAttemptNumber = "attempt_number"
|
||||||
StoreAttemptTime = "attempt_time"
|
StoreAttemptTime = "attempt_time"
|
||||||
StoreLocked = "locked"
|
StoreLocked = "locked"
|
||||||
@@ -22,7 +20,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
authboss.RegisterModule(ModuleName, &Lock{})
|
authboss.RegisterModule("lock", &Lock{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock module
|
// Lock module
|
||||||
|
@@ -17,10 +17,6 @@ import (
|
|||||||
"gopkg.in/authboss.v0/internal/response"
|
"gopkg.in/authboss.v0/internal/response"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
ModuleName = "oauth2"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errOAuthStateValidation = errors.New("Could not validate oauth2 state param")
|
errOAuthStateValidation = errors.New("Could not validate oauth2 state param")
|
||||||
)
|
)
|
||||||
@@ -31,7 +27,7 @@ type OAuth2 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
authboss.RegisterModule(ModuleName, &OAuth2{})
|
authboss.RegisterModule("oauth2", &OAuth2{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize module
|
// Initialize module
|
||||||
|
@@ -28,8 +28,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModuleName = "recover"
|
|
||||||
|
|
||||||
methodGET = "GET"
|
methodGET = "GET"
|
||||||
methodPOST = "POST"
|
methodPOST = "POST"
|
||||||
|
|
||||||
@@ -58,7 +56,7 @@ type RecoverStorer interface {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
m := &Recover{}
|
m := &Recover{}
|
||||||
authboss.RegisterModule(ModuleName, m)
|
authboss.RegisterModule("recover", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recover module
|
// Recover module
|
||||||
@@ -197,7 +195,7 @@ func newToken() (encodedToken, encodedChecksum string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var goRecoverEmail = func(r *Recover, ctx *authboss.Context, to, encodedToken string) {
|
var goRecoverEmail = func(r *Recover, ctx *authboss.Context, to, encodedToken string) {
|
||||||
if ctx.DisableGoroutines {
|
if ctx.MailMaker != nil {
|
||||||
r.sendRecoverEmail(ctx, to, encodedToken)
|
r.sendRecoverEmail(ctx, to, encodedToken)
|
||||||
} else {
|
} else {
|
||||||
go r.sendRecoverEmail(ctx, to, encodedToken)
|
go r.sendRecoverEmail(ctx, to, encodedToken)
|
||||||
|
@@ -268,7 +268,7 @@ func TestRecover_sendRecoverMail_FailToSend(t *testing.T) {
|
|||||||
mailer.SendErr = "failed to send"
|
mailer.SendErr = "failed to send"
|
||||||
r.Mailer = mailer
|
r.Mailer = mailer
|
||||||
|
|
||||||
r.sendRecoverEmail("", "")
|
r.sendRecoverEmail(r.NewContext(), "", "")
|
||||||
|
|
||||||
if !strings.Contains(logger.String(), "failed to send") {
|
if !strings.Contains(logger.String(), "failed to send") {
|
||||||
t.Error("Expected logged to have msg:", "failed to send")
|
t.Error("Expected logged to have msg:", "failed to send")
|
||||||
@@ -285,7 +285,7 @@ func TestRecover_sendRecoverEmail(t *testing.T) {
|
|||||||
r.RootURL = "bar"
|
r.RootURL = "bar"
|
||||||
r.Mailer = mailer
|
r.Mailer = mailer
|
||||||
|
|
||||||
r.sendRecoverEmail("a@b.c", "abc=")
|
r.sendRecoverEmail(r.NewContext(), "a@b.c", "abc=")
|
||||||
if len(mailer.Last.To) != 1 {
|
if len(mailer.Last.To) != 1 {
|
||||||
t.Error("Expected 1 to email")
|
t.Error("Expected 1 to email")
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModuleName = "register"
|
|
||||||
|
|
||||||
tplRegister = "register.html.tpl"
|
tplRegister = "register.html.tpl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,7 +24,7 @@ type RegisterStorer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
authboss.RegisterModule(ModuleName, &Register{})
|
authboss.RegisterModule("register", &Register{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register module.
|
// Register module.
|
||||||
|
@@ -14,8 +14,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModuleName = "remember"
|
|
||||||
|
|
||||||
nRandBytes = 32
|
nRandBytes = 32
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,7 +39,7 @@ type RememberStorer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
authboss.RegisterModule(ModuleName, &Remember{})
|
authboss.RegisterModule("remember", &Remember{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember module
|
// Remember module
|
||||||
|
Reference in New Issue
Block a user