Skip to content

Commit

Permalink
chore: refactor arg types
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Jul 25, 2024
1 parent 031796b commit a36c511
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/api/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (ts *AuthTestSuite) TestParseJWTClaims() {

userJwtToken := jwt.NewWithClaims(signingMethod, userClaims)
require.NoError(ts.T(), err)
userJwtToken.Header["kid"] = (*jwk).KeyID()
userJwtToken.Header["kid"] = jwk.KeyID()
userJwt, err := userJwtToken.SignedString(signingKey)
require.NoError(ts.T(), err)

Expand Down
2 changes: 1 addition & 1 deletion internal/api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user
}

if _, ok := token.Header["kid"]; !ok {
kid := (*signingJwk).KeyID()
kid := signingJwk.KeyID()
token.Header["kid"] = kid
}

Expand Down
2 changes: 1 addition & 1 deletion internal/conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ func (config *GlobalConfiguration) ApplyDefaults() error {
if config.JWT.ValidMethods == nil {
config.JWT.ValidMethods = []string{}
for _, key := range config.JWT.Keys {
alg := GetSigningAlg(&key.PublicKey)
alg := GetSigningAlg(key.PublicKey)
config.JWT.ValidMethods = append(config.JWT.ValidMethods, alg.Alg())
}

Expand Down
16 changes: 8 additions & 8 deletions internal/conf/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ func (j *JwtKeysDecoder) Validate() error {
return nil
}

func GetSigningJwk(config *JWTConfiguration) (*jwk.Key, error) {
func GetSigningJwk(config *JWTConfiguration) (jwk.Key, error) {
for _, key := range config.Keys {
if key.PrivateKey.KeyUsage() == "enc" {
return &key.PrivateKey, nil
return key.PrivateKey, nil
}
}
return nil, fmt.Errorf("no signing key found")
}

func GetSigningKey(k *jwk.Key) (any, error) {
func GetSigningKey(k jwk.Key) (any, error) {
var key any
switch (*k).KeyType() {
switch k.KeyType() {
case jwa.OctetSeq:
key = []byte{}
case jwa.EC:
Expand All @@ -102,18 +102,18 @@ func GetSigningKey(k *jwk.Key) (any, error) {
case jwa.InvalidKeyType:
return nil, jwt.ErrInvalidKeyType
}
if err := (*k).Raw(&key); err != nil {
if err := k.Raw(&key); err != nil {
return nil, err
}
return key, nil
}

func GetSigningAlg(k *jwk.Key) jwt.SigningMethod {
func GetSigningAlg(k jwk.Key) jwt.SigningMethod {
if k == nil {
return jwt.SigningMethodHS256
}

switch (*k).Algorithm().String() {
switch (k).Algorithm().String() {
case "RS256":
return jwt.SigningMethodRS256
case "RS512":
Expand All @@ -132,7 +132,7 @@ func GetSigningAlg(k *jwk.Key) jwt.SigningMethod {

func FindPublicKeyByKid(kid string, config *JWTConfiguration) (any, error) {
if k, ok := config.Keys[kid]; ok {
key, err := GetSigningKey(&k.PublicKey)
key, err := GetSigningKey(k.PublicKey)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a36c511

Please sign in to comment.