mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-09 09:56:48 +00:00
refactor: move autologin to handler pkg
This commit is contained in:
@@ -8,17 +8,17 @@ import (
|
||||
"github.com/nais/wonderwall/pkg/config"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
type AutoLogin struct {
|
||||
Enabled bool
|
||||
IgnorePatterns []string
|
||||
}
|
||||
|
||||
func (o *Options) NeedsLogin(r *http.Request, isAuthenticated bool) bool {
|
||||
if isAuthenticated || !o.Enabled {
|
||||
func (a *AutoLogin) NeedsLogin(r *http.Request, isAuthenticated bool) bool {
|
||||
if isAuthenticated || !a.Enabled {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, pattern := range o.IgnorePatterns {
|
||||
for _, pattern := range a.IgnorePatterns {
|
||||
path := r.URL.Path
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
path = "/" + path
|
||||
@@ -33,7 +33,7 @@ func (o *Options) NeedsLogin(r *http.Request, isAuthenticated bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func NewOptions(cfg *config.Config) (*Options, error) {
|
||||
func New(cfg *config.Config) (*AutoLogin, error) {
|
||||
seen := make(map[string]bool)
|
||||
patterns := make([]string, 0)
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewOptions(cfg *config.Config) (*Options, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return &Options{
|
||||
return &AutoLogin{
|
||||
Enabled: cfg.AutoLogin,
|
||||
IgnorePatterns: patterns,
|
||||
}, nil
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"net/http/httputil"
|
||||
"time"
|
||||
|
||||
"github.com/nais/wonderwall/pkg/autologin"
|
||||
"github.com/nais/wonderwall/pkg/config"
|
||||
"github.com/nais/wonderwall/pkg/cookie"
|
||||
"github.com/nais/wonderwall/pkg/crypto"
|
||||
"github.com/nais/wonderwall/pkg/handler/autologin"
|
||||
"github.com/nais/wonderwall/pkg/loginstatus"
|
||||
"github.com/nais/wonderwall/pkg/middleware"
|
||||
"github.com/nais/wonderwall/pkg/openid/client"
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
AutoLogin *autologin.Options
|
||||
AutoLogin *autologin.AutoLogin
|
||||
Client client.Client
|
||||
Config *config.Config
|
||||
CookieOptions cookie.Options
|
||||
@@ -42,7 +42,7 @@ func NewHandler(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
autoLogin, err := autologin.NewOptions(cfg)
|
||||
autoLogin, err := autologin.New(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user