mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
refactor: make key props public
This commit is contained in:
parent
c1f9393dd1
commit
a8ba658b63
@ -28,7 +28,7 @@ func WithDeprecatedKeys(v ...Key) Option {
|
|||||||
return func(o *JWT) {
|
return func(o *JWT) {
|
||||||
deprecatedKeys := make(map[string]Key, len(v))
|
deprecatedKeys := make(map[string]Key, len(v))
|
||||||
for _, key := range deprecatedKeys {
|
for _, key := range deprecatedKeys {
|
||||||
deprecatedKeys[key.id] = key
|
deprecatedKeys[key.ID] = key
|
||||||
}
|
}
|
||||||
o.DeprecatedKeys = deprecatedKeys
|
o.DeprecatedKeys = deprecatedKeys
|
||||||
}
|
}
|
||||||
@ -53,8 +53,8 @@ func New(key Key, opts ...Option) *JWT {
|
|||||||
func (j *JWT) GetSignedToken(claims jwt.Claims) (string, error) {
|
func (j *JWT) GetSignedToken(claims jwt.Claims) (string, error) {
|
||||||
// create token
|
// create token
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||||
token.Header["kid"] = j.Key.id
|
token.Header["kid"] = j.Key.ID
|
||||||
return token.SignedString(j.Key.private)
|
return token.SignedString(j.Key.Private)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JWT) ParseWithClaims(token string, claims jwt.Claims) (*jwt.Token, error) {
|
func (j *JWT) ParseWithClaims(token string, claims jwt.Claims) (*jwt.Token, error) {
|
||||||
|
|||||||
@ -12,20 +12,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Key struct {
|
type Key struct {
|
||||||
// id (required) represents the key identifier e.g. the md5 representation of the public key
|
// ID (required) represents the key identifier e.g. the md5 representation of the public key
|
||||||
id string
|
ID string
|
||||||
// public (required) rsa key
|
// Public (required) rsa key
|
||||||
public *rsa.PublicKey
|
Public *rsa.PublicKey
|
||||||
// private (optional) rsa key
|
// Private (optional) rsa key
|
||||||
private *rsa.PrivateKey
|
Private *rsa.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKey return a new Key
|
// NewKey return a new Key
|
||||||
func NewKey(id string, public *rsa.PublicKey, private *rsa.PrivateKey) Key {
|
func NewKey(id string, public *rsa.PublicKey, private *rsa.PrivateKey) Key {
|
||||||
return Key{
|
return Key{
|
||||||
id: id,
|
ID: id,
|
||||||
public: public,
|
Public: public,
|
||||||
private: private,
|
Private: private,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,11 +15,11 @@ func DefaultKeyFunc(key Key, deprecatedKeys map[string]Key) jwt.Keyfunc {
|
|||||||
} else if kidString, ok := kid.(string); !ok {
|
} else if kidString, ok := kid.(string); !ok {
|
||||||
return nil, errors.New("invalid key identifier type")
|
return nil, errors.New("invalid key identifier type")
|
||||||
} else if oldKey, ok := deprecatedKeys[kidString]; ok {
|
} else if oldKey, ok := deprecatedKeys[kidString]; ok {
|
||||||
return oldKey.public, nil
|
return oldKey.Public, nil
|
||||||
} else if kidString == key.id {
|
} else if kidString == key.ID {
|
||||||
return key.public, nil
|
return key.Public, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("unknown key identifier: " + kidString + " (" + key.id + ")")
|
return nil, errors.New("unknown key identifier: " + kidString + " (" + key.ID + ")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user