53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
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.ErrorPage,
|
|
)
|
|
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
|
|
}
|