pkg/oidc: Replace interface{} with any

Signed-off-by: Thomas Hipp <thomashipp@gmail.com>
This commit is contained in:
Thomas Hipp 2023-09-26 19:54:48 +02:00
parent 4e6033896d
commit 868cf39632
No known key found for this signature in database
GPG key ID: 36F3DB891755E09B
8 changed files with 22 additions and 22 deletions

View file

@ -151,7 +151,7 @@ func (e *Error) WithParent(err error) *Error {
return e return e
} }
func (e *Error) WithDescription(desc string, args ...interface{}) *Error { func (e *Error) WithDescription(desc string, args ...any) *Error {
e.Description = fmt.Sprintf(desc, args...) e.Description = fmt.Sprintf(desc, args...)
return e return e
} }

View file

@ -46,8 +46,8 @@ func GetKeyIDAndAlg(jws *jose.JSONWebSignature) (string, string) {
// //
// will return false none or multiple match // will return false none or multiple match
// //
//deprecated: use FindMatchingKey which will return an error (more specific) instead of just a bool // deprecated: use FindMatchingKey which will return an error (more specific) instead of just a bool
//moved implementation already to FindMatchingKey // moved implementation already to FindMatchingKey
func FindKey(keyID, use, expectedAlg string, keys ...jose.JSONWebKey) (jose.JSONWebKey, bool) { func FindKey(keyID, use, expectedAlg string, keys ...jose.JSONWebKey) (jose.JSONWebKey, bool) {
key, err := FindMatchingKey(keyID, use, expectedAlg, keys...) key, err := FindMatchingKey(keyID, use, expectedAlg, keys...)
return key, err == nil return key, err == nil
@ -91,7 +91,7 @@ func FindMatchingKey(keyID, use, expectedAlg string, keys ...jose.JSONWebKey) (k
return key, ErrKeyNone return key, ErrKeyNone
} }
func algToKeyType(key interface{}, alg string) bool { func algToKeyType(key any, alg string) bool {
switch alg[0] { switch alg[0] {
case 'R', 'P': case 'R', 'P':
_, ok := key.(*rsa.PublicKey) _, ok := key.(*rsa.PublicKey)

View file

@ -17,7 +17,7 @@ const dataDir = "regression_data"
// jsonFilename builds a filename for the regression testdata. // jsonFilename builds a filename for the regression testdata.
// dataDir/<type_name>.json // dataDir/<type_name>.json
func jsonFilename(obj interface{}) string { func jsonFilename(obj any) string {
name := fmt.Sprintf("%T.json", obj) name := fmt.Sprintf("%T.json", obj)
return path.Join( return path.Join(
dataDir, dataDir,
@ -25,13 +25,13 @@ func jsonFilename(obj interface{}) string {
) )
} }
func encodeJSON(t *testing.T, w io.Writer, obj interface{}) { func encodeJSON(t *testing.T, w io.Writer, obj any) {
enc := json.NewEncoder(w) enc := json.NewEncoder(w)
enc.SetIndent("", "\t") enc.SetIndent("", "\t")
require.NoError(t, enc.Encode(obj)) require.NoError(t, enc.Encode(obj))
} }
var regressionData = []interface{}{ var regressionData = []any{
accessTokenData, accessTokenData,
idTokenData, idTokenData,
introspectionResponseData, introspectionResponseData,

View file

@ -222,7 +222,7 @@ type JWTProfileAssertionClaims struct {
Expiration Time `json:"exp"` Expiration Time `json:"exp"`
IssuedAt Time `json:"iat"` IssuedAt Time `json:"iat"`
Claims map[string]interface{} `json:"-"` Claims map[string]any `json:"-"`
} }
type jpaAlias JWTProfileAssertionClaims type jpaAlias JWTProfileAssertionClaims
@ -262,7 +262,7 @@ func JWTProfileDelegatedSubject(sub string) func(*JWTProfileAssertionClaims) {
} }
} }
func JWTProfileCustomClaim(key string, value interface{}) func(*JWTProfileAssertionClaims) { func JWTProfileCustomClaim(key string, value any) func(*JWTProfileAssertionClaims) {
return func(j *JWTProfileAssertionClaims) { return func(j *JWTProfileAssertionClaims) {
j.Claims[key] = value j.Claims[key] = value
} }
@ -292,7 +292,7 @@ func NewJWTProfileAssertion(userID, keyID string, audience []string, key []byte,
IssuedAt: FromTime(time.Now().UTC()), IssuedAt: FromTime(time.Now().UTC()),
Expiration: FromTime(time.Now().Add(1 * time.Hour).UTC()), Expiration: FromTime(time.Now().Add(1 * time.Hour).UTC()),
Audience: audience, Audience: audience,
Claims: make(map[string]interface{}), Claims: make(map[string]any),
} }
for _, opt := range opts { for _, opt := range opts {

View file

@ -130,7 +130,7 @@ type JWTTokenRequest struct {
IssuedAt Time `json:"iat"` IssuedAt Time `json:"iat"`
ExpiresAt Time `json:"exp"` ExpiresAt Time `json:"exp"`
private map[string]interface{} private map[string]any
} }
func (j *JWTTokenRequest) MarshalJSON() ([]byte, error) { func (j *JWTTokenRequest) MarshalJSON() ([]byte, error) {
@ -171,7 +171,7 @@ func (j *JWTTokenRequest) UnmarshalJSON(data []byte) error {
return nil return nil
} }
func (j *JWTTokenRequest) GetCustomClaim(key string) interface{} { func (j *JWTTokenRequest) GetCustomClaim(key string) any {
return j.private[key] return j.private[key]
} }

View file

@ -29,7 +29,7 @@ var (
accessTokenData = &AccessTokenClaims{ accessTokenData = &AccessTokenClaims{
TokenClaims: tokenClaimsData, TokenClaims: tokenClaimsData,
Scopes: []string{"email", "phone"}, Scopes: []string{"email", "phone"},
Claims: map[string]interface{}{ Claims: map[string]any{
"foo": "bar", "foo": "bar",
}, },
} }
@ -43,7 +43,7 @@ var (
UserInfoEmail: userInfoData.UserInfoEmail, UserInfoEmail: userInfoData.UserInfoEmail,
UserInfoPhone: userInfoData.UserInfoPhone, UserInfoPhone: userInfoData.UserInfoPhone,
Address: userInfoData.Address, Address: userInfoData.Address,
Claims: map[string]interface{}{ Claims: map[string]any{
"foo": "bar", "foo": "bar",
}, },
} }
@ -64,7 +64,7 @@ var (
UserInfoEmail: userInfoData.UserInfoEmail, UserInfoEmail: userInfoData.UserInfoEmail,
UserInfoPhone: userInfoData.UserInfoPhone, UserInfoPhone: userInfoData.UserInfoPhone,
Address: userInfoData.Address, Address: userInfoData.Address,
Claims: map[string]interface{}{ Claims: map[string]any{
"foo": "bar", "foo": "bar",
}, },
} }
@ -102,7 +102,7 @@ var (
PostalCode: "666-666", PostalCode: "666-666",
Country: "Moon", Country: "Moon",
}, },
Claims: map[string]interface{}{ Claims: map[string]any{
"foo": "bar", "foo": "bar",
}, },
} }
@ -114,7 +114,7 @@ var (
Audience: Audience{"foo", "bar"}, Audience: Audience{"foo", "bar"},
Expiration: 12345, Expiration: 12345,
IssuedAt: 12000, IssuedAt: 12000,
Claims: map[string]interface{}{ Claims: map[string]any{
"foo": "bar", "foo": "bar",
}, },
} }
@ -181,7 +181,7 @@ func TestIDTokenClaims_SetUserInfo(t *testing.T) {
UserInfoEmail: userInfoData.UserInfoEmail, UserInfoEmail: userInfoData.UserInfoEmail,
UserInfoPhone: userInfoData.UserInfoPhone, UserInfoPhone: userInfoData.UserInfoPhone,
Address: userInfoData.Address, Address: userInfoData.Address,
Claims: map[string]interface{}{ Claims: map[string]any{
"foo": "bar", "foo": "bar",
}, },
} }

View file

@ -17,13 +17,13 @@ import (
type Audience []string type Audience []string
func (a *Audience) UnmarshalJSON(text []byte) error { func (a *Audience) UnmarshalJSON(text []byte) error {
var i interface{} var i any
err := json.Unmarshal(text, &i) err := json.Unmarshal(text, &i)
if err != nil { if err != nil {
return err return err
} }
switch aud := i.(type) { switch aud := i.(type) {
case []interface{}: case []any:
*a = make([]string, len(aud)) *a = make([]string, len(aud))
for i, audience := range aud { for i, audience := range aud {
(*a)[i] = audience.(string) (*a)[i] = audience.(string)
@ -177,7 +177,7 @@ func (s *SpaceDelimitedArray) UnmarshalJSON(data []byte) error {
return nil return nil
} }
func (s *SpaceDelimitedArray) Scan(src interface{}) error { func (s *SpaceDelimitedArray) Scan(src any) error {
if src == nil { if src == nil {
*s = nil *s = nil
return nil return nil

View file

@ -85,7 +85,7 @@ func DecryptToken(tokenString string) (string, error) {
return tokenString, nil // TODO: impl return tokenString, nil // TODO: impl
} }
func ParseToken(tokenString string, claims interface{}) ([]byte, error) { func ParseToken(tokenString string, claims any) ([]byte, error) {
parts := strings.Split(tokenString, ".") parts := strings.Split(tokenString, ".")
if len(parts) != 3 { if len(parts) != 3 {
return nil, fmt.Errorf("%w: token contains an invalid number of segments", ErrParse) return nil, fmt.Errorf("%w: token contains an invalid number of segments", ErrParse)