modularised webserver and auth systems
This commit is contained in:
52
cmd/projectreshoot/auth.go
Normal file
52
cmd/projectreshoot/auth.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"projectreshoot/internal/config"
|
||||
"projectreshoot/internal/handler"
|
||||
"projectreshoot/internal/models"
|
||||
"projectreshoot/pkg/contexts"
|
||||
|
||||
"git.haelnorr.com/h/golib/hlog"
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
"git.haelnorr.com/h/golib/hwsauth"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func setupAuth(
|
||||
config *config.Config,
|
||||
logger *hlog.Logger,
|
||||
conn *sql.DB,
|
||||
server *hws.Server,
|
||||
ignoredPaths []string,
|
||||
) (*hwsauth.Authenticator[*models.User], error) {
|
||||
auth, err := hwsauth.NewAuthenticator(
|
||||
models.GetUserFromID,
|
||||
server,
|
||||
conn,
|
||||
logger,
|
||||
handler.NewErrorPage,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "hwsauth.NewAuthenticator")
|
||||
}
|
||||
|
||||
auth.SSL = config.SSL
|
||||
auth.AccessTokenExpiry = config.AccessTokenExpiry
|
||||
auth.RefreshTokenExpiry = config.RefreshTokenExpiry
|
||||
auth.TokenFreshTime = config.TokenFreshTime
|
||||
auth.TrustedHost = config.TrustedHost
|
||||
auth.SecretKey = config.SecretKey
|
||||
auth.LandingPage = "/profile"
|
||||
|
||||
auth.IgnorePaths(ignoredPaths...)
|
||||
|
||||
err = auth.Initialise()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "auth.Initialise")
|
||||
}
|
||||
|
||||
contexts.CurrentUser = auth.CurrentModel
|
||||
|
||||
return auth, nil
|
||||
}
|
||||
Reference in New Issue
Block a user