shiori/internal/webserver/server.go
Federico Scodelaro 9f6a4c39d4
feat: support proxy forward headers authentication (#1105)
* feat: Add SSO forward header

* fix: Use domain layer

* test: Some test

* chore: Print new values when debugging

* chore: Rename enabled envvar

* fix: Wrongly parsing remote ip

* fix: Always validate token. NPE on validateSession

* fix: Dont overwrite token when sso

* fix: Best effort to get ip. Parse as ip:port and then as ip

* fix: Forgot to update handler version

* fix: Forgot to commit changes

* test: GetAccountByUsername

* chore: Rename some variables

* chore: return error from ssoAccount

* refactor: Extract sso proxy auth to own middleware

* fix: Dont panic if not sso account on legacy validate session

* ci: gofmt

---------

Co-authored-by: Felipe Martin <812088+fmartingr@users.noreply.github.com>
2025-07-12 12:11:42 +02:00

46 lines
1.1 KiB
Go

package webserver
import (
"net"
"time"
"github.com/go-shiori/shiori/internal/model"
cch "github.com/patrickmn/go-cache"
)
// Config is parameter that used for starting web server
type Config struct {
DB model.DB
DataDir string
ServerAddress string
ServerPort int
RootPath string
Log bool
}
// GetLegacyHandler returns a legacy handler to use with the new webserver
func GetLegacyHandler(cfg Config, dependencies model.Dependencies) *Handler {
plainIPs := dependencies.Config().Http.SSOProxyAuthTrusted
trustedIPs := make([]*net.IPNet, len(plainIPs))
for i, ip := range plainIPs {
_, ipNet, err := net.ParseCIDR(ip)
if err != nil {
dependencies.Logger().WithError(err).WithField("ip", ip).Error("Failed to parse trusted ip cidr")
continue
}
trustedIPs[i] = ipNet
}
return &Handler{
DB: cfg.DB,
DataDir: cfg.DataDir,
UserCache: cch.New(time.Hour, 10*time.Minute),
// SessionCache: cch.New(time.Hour, 10*time.Minute),
ArchiveCache: cch.New(time.Minute, 5*time.Minute),
RootPath: cfg.RootPath,
Log: cfg.Log,
dependencies: dependencies,
trustedIPs: trustedIPs,
}
}