diff --git a/internal/data/config.go b/internal/data/config.go index f2547f04..8514f671 100644 --- a/internal/data/config.go +++ b/internal/data/config.go @@ -100,12 +100,16 @@ func SetPAM(details PAM) error { func GetPAM() (details PAM, err error) { - v, err := getString(PamDetailsKey) + response, err := etcd.Get(context.Background(), OidcDetailsKey) if err != nil { - return PAM{}, nil + return PAM{}, err } - err = json.Unmarshal([]byte(v), &details) + if len(response.Kvs) == 0 { + return PAM{}, errors.New("no PAM settings found") + } + + err = json.Unmarshal(response.Kvs[0].Value, &details) return } @@ -121,12 +125,16 @@ func SetOidc(details OIDC) error { func GetOidc() (details OIDC, err error) { - v, err := getString(OidcDetailsKey) + response, err := etcd.Get(context.Background(), OidcDetailsKey) if err != nil { - return OIDC{}, nil + return OIDC{}, err + } + + if len(response.Kvs) == 0 { + return OIDC{}, errors.New("no oidc settings found") } - err = json.Unmarshal([]byte(v), &details) + err = json.Unmarshal(response.Kvs[0].Value, &details) return } diff --git a/internal/webserver/authenticators/oidc.go b/internal/webserver/authenticators/oidc.go index 540fa17b..3c885b8f 100644 --- a/internal/webserver/authenticators/oidc.go +++ b/internal/webserver/authenticators/oidc.go @@ -52,6 +52,11 @@ func (o *Oidc) Init() error { return errors.New("failed to get random key: " + err.Error()) } + o.details, err = data.GetOidc() + if err != nil { + return err + } + cookieHandler := httphelper.NewCookieHandler(key, key, httphelper.WithUnsecure()) options := []rp.Option{ @@ -71,12 +76,6 @@ func (o *Oidc) Init() error { u.Path = path.Join(u.Path, "/authorise/oidc/") log.Println("OIDC callback: ", u.String()) - - o.details, err = data.GetOidc() - if err != nil { - return err - } - log.Println("Connecting to OIDC provider: ", o.details.IssuerURL) o.provider, err = rp.NewRelyingPartyOIDC(o.details.IssuerURL, o.details.ClientID, o.details.ClientSecret, u.String(), []string{"openid"}, options...)