From a6ced1f99fdd857d263b9dada5060fbd9c6937bf Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 20 Apr 2023 11:27:21 +0200 Subject: [PATCH] Simplifiy Unmarshall function for stringAsBool struct Co-authored-by: Julian Koberg Signed-off-by: Christian Richter --- ocis-pkg/oidc/client.go | 12 +++++------- services/proxy/pkg/middleware/oidc_auth.go | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/ocis-pkg/oidc/client.go b/ocis-pkg/oidc/client.go index 0a27708363..f06837a155 100644 --- a/ocis-pkg/oidc/client.go +++ b/ocis-pkg/oidc/client.go @@ -10,6 +10,7 @@ import ( "io" "mime" "net/http" + "strconv" "strings" "sync" "time" @@ -176,14 +177,11 @@ type stringAsBool bool // Claims unmarshals the raw JSON string into a bool. func (sb *stringAsBool) UnmarshalJSON(b []byte) error { - switch string(b) { - case "true", `"true"`: - *sb = true - case "false", `"false"`: - *sb = false - default: - return errors.New("invalid value for boolean") + v, err := strconv.ParseBool(string(b)) + if err != nil { + return err } + *sb = stringAsBool(v) return nil } diff --git a/services/proxy/pkg/middleware/oidc_auth.go b/services/proxy/pkg/middleware/oidc_auth.go index b8a57e1c6a..1156f2b9a1 100644 --- a/services/proxy/pkg/middleware/oidc_auth.go +++ b/services/proxy/pkg/middleware/oidc_auth.go @@ -70,7 +70,6 @@ func (m *OIDCAuthenticator) getClaims(token string, req *http.Request) (map[stri m.Logger.Error().Err(err).Msg("could not unmarshal userinfo") } - // TODO: use mClaims aClaims, _, err := m.oidcClient.VerifyAccessToken(req.Context(), token) if err != nil { return nil, errors.Wrap(err, "failed to verify access token")