mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-14 12:26:34 +00:00
refactor(openid): clean up client and provider
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/nais/wonderwall/pkg/cookie"
|
||||
"github.com/nais/wonderwall/pkg/crypto"
|
||||
errorhandler "github.com/nais/wonderwall/pkg/handler/error"
|
||||
"github.com/nais/wonderwall/pkg/loginstatus"
|
||||
logentry "github.com/nais/wonderwall/pkg/middleware"
|
||||
"github.com/nais/wonderwall/pkg/openid"
|
||||
openidclient "github.com/nais/wonderwall/pkg/openid/client"
|
||||
@@ -27,11 +26,10 @@ type Source interface {
|
||||
GetCookieOptsPathAware(r *http.Request) cookie.Options
|
||||
GetCrypter() crypto.Crypter
|
||||
GetErrorHandler() errorhandler.Handler
|
||||
GetLoginstatus() *loginstatus.Loginstatus
|
||||
}
|
||||
|
||||
func Handler(src Source, w http.ResponseWriter, r *http.Request) {
|
||||
login, err := src.GetClient().Login(r, src.GetLoginstatus())
|
||||
login, err := src.GetClient().Login(r)
|
||||
if err != nil {
|
||||
if errors.Is(err, openidclient.InvalidSecurityLevelError) || errors.Is(err, openidclient.InvalidLocaleError) {
|
||||
src.GetErrorHandler().BadRequest(w, r, err)
|
||||
|
||||
@@ -29,7 +29,6 @@ type Source interface {
|
||||
GetCrypter() crypto.Crypter
|
||||
GetErrorHandler() errorhandler.Handler
|
||||
GetLoginstatus() *loginstatus.Loginstatus
|
||||
GetProvider() openidclient.OpenIDProvider
|
||||
GetSessions() *session.Handler
|
||||
GetSessionConfig() config.Session
|
||||
}
|
||||
@@ -48,7 +47,7 @@ func Handler(src Source, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
loginCallback, err := src.GetClient().LoginCallback(r, src.GetProvider(), loginCookie)
|
||||
loginCallback, err := src.GetClient().LoginCallback(r, loginCookie)
|
||||
if err != nil {
|
||||
src.GetErrorHandler().InternalError(w, r, err)
|
||||
return
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
func NewHandler(
|
||||
cfg *config.Config,
|
||||
cookieOpts cookie.Options,
|
||||
jwksProvider client.JwksProvider,
|
||||
openidConfig openidconfig.Config,
|
||||
openidProvider client.OpenIDProvider,
|
||||
crypter crypto.Crypter,
|
||||
) (*StandardHandler, error) {
|
||||
autoLogin, err := autologin.New(cfg)
|
||||
@@ -32,7 +32,9 @@ func NewHandler(
|
||||
Timeout: time.Second * 10,
|
||||
}
|
||||
|
||||
openidClient := client.NewClient(openidConfig)
|
||||
loginstatusClient := loginstatus.NewClient(cfg.Loginstatus, httpClient)
|
||||
|
||||
openidClient := client.NewClient(openidConfig, loginstatusClient, jwksProvider)
|
||||
openidClient.SetHttpClient(httpClient)
|
||||
|
||||
sessionHandler, err := session.NewHandler(cfg, openidConfig, crypter, openidClient)
|
||||
@@ -52,9 +54,8 @@ func NewHandler(
|
||||
cookieOptions: cookieOpts,
|
||||
crypter: crypter,
|
||||
ingresses: ingresses,
|
||||
loginstatus: loginstatus.NewClient(cfg.Loginstatus, httpClient),
|
||||
loginstatus: loginstatusClient,
|
||||
openidConfig: openidConfig,
|
||||
provider: openidProvider,
|
||||
sessions: sessionHandler,
|
||||
upstreamProxy: reverseproxy.New(cfg.UpstreamHost),
|
||||
}, nil
|
||||
|
||||
@@ -36,7 +36,6 @@ type StandardHandler struct {
|
||||
ingresses *ingress.Ingresses
|
||||
loginstatus *loginstatus.Loginstatus
|
||||
openidConfig openidconfig.Config
|
||||
provider openidclient.OpenIDProvider
|
||||
sessions *session.Handler
|
||||
upstreamProxy *reverseproxy.ReverseProxy
|
||||
}
|
||||
@@ -91,10 +90,6 @@ func (s *StandardHandler) GetPath(r *http.Request) string {
|
||||
return path
|
||||
}
|
||||
|
||||
func (s *StandardHandler) GetProvider() openidclient.OpenIDProvider {
|
||||
return s.provider
|
||||
}
|
||||
|
||||
func (s *StandardHandler) GetProviderName() string {
|
||||
return s.openidConfig.Provider().Name()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user