Skip to content

Commit

Permalink
Dont decode json object as string, fix pam as well closes #106
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed May 7, 2024
1 parent fcb6ed4 commit 95df3e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
20 changes: 14 additions & 6 deletions internal/data/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
11 changes: 5 additions & 6 deletions internal/webserver/authenticators/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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...)
Expand Down

0 comments on commit 95df3e2

Please sign in to comment.