oidc icon indicating copy to clipboard operation
oidc copied to clipboard

GetClaim() returning interface is awkward to use. Use output parameter instead?

Open arianvp opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

The following code is awkward as I need to guess that the structure that GetClaim() returns is map[string]string.

		val, ok := introspectionResponse.GetClaim("cnf").(map[string]string)
		if !ok {
			http.Error(rw, "", http.StatusUnauthorized)
			return
		}

		expectedClientCertificateHash, err := base64.URLEncoding.DecodeString(val["x5t#S256"])
		if err != nil {
			http.Error(rw, "", http.StatusUnauthorized)
			return
		}
		if !bytes.Equal(clientCertificateHash[:], expectedClientCertificateHash) {
			http.Error(rw, "", http.StatusUnauthorized)
			return
		}

Describe the solution you'd like

I'd prefer GetClaim() to take an output parameter instead. so that I can marshal safely to my own struct type:

func (r IntrospectionResponse) GetClaim(key string, out interface{}) error {...}
type ConfirmationClaim struct {
        CertificateThumbprint string `json:"x5t#S256"`
}

var cnf ConfirmationClaim
err := introspectionResponse.GetClaim("cnf", &cnf)
if err != nil { ... }
expectedClientCertificateHash, err := base64.URLEncoding.DecodeString(cnf.CertificateThumbprint)
if err != nil { ... }
if !bytes.Equal(clientCertificateHash[:], cnf.CertificateThumbprint {
	http.Error(rw, "", http.StatusUnauthorized)
	return
}

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

arianvp avatar May 18 '22 08:05 arianvp

Hi @arianvp - I agree that this can be improved 😁

Currently all hands are in the version 2 prepwork for ZITADEL, so it might take 2-4 weeks before someone can get a hold of this issue. Hope thats not too bad for you.

fforootd avatar May 18 '22 22:05 fforootd

No rush. The code works as is. It's just awkward.

arianvp avatar May 19 '22 09:05 arianvp

#283 should improve this. If you have any other feedback, please let us know

muhlemmer avatar Mar 13 '23 10:03 muhlemmer