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) {
|
||||
deprecatedKeys := make(map[string]Key, len(v))
|
||||
for _, key := range deprecatedKeys {
|
||||
deprecatedKeys[key.id] = key
|
||||
deprecatedKeys[key.ID] = key
|
||||
}
|
||||
o.DeprecatedKeys = deprecatedKeys
|
||||
}
|
||||
@ -53,8 +53,8 @@ func New(key Key, opts ...Option) *JWT {
|
||||
func (j *JWT) GetSignedToken(claims jwt.Claims) (string, error) {
|
||||
// create token
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)
|
||||
token.Header["kid"] = j.Key.id
|
||||
return token.SignedString(j.Key.private)
|
||||
token.Header["kid"] = j.Key.ID
|
||||
return token.SignedString(j.Key.Private)
|
||||
}
|
||||
|
||||
func (j *JWT) ParseWithClaims(token string, claims jwt.Claims) (*jwt.Token, error) {
|
||||
|
||||
@ -12,20 +12,20 @@ import (
|
||||
)
|
||||
|
||||
type Key struct {
|
||||
// id (required) represents the key identifier e.g. the md5 representation of the public key
|
||||
id string
|
||||
// public (required) rsa key
|
||||
public *rsa.PublicKey
|
||||
// private (optional) rsa key
|
||||
private *rsa.PrivateKey
|
||||
// ID (required) represents the key identifier e.g. the md5 representation of the public key
|
||||
ID string
|
||||
// Public (required) rsa key
|
||||
Public *rsa.PublicKey
|
||||
// Private (optional) rsa key
|
||||
Private *rsa.PrivateKey
|
||||
}
|
||||
|
||||
// NewKey return a new Key
|
||||
func NewKey(id string, public *rsa.PublicKey, private *rsa.PrivateKey) Key {
|
||||
return Key{
|
||||
id: id,
|
||||
public: public,
|
||||
private: private,
|
||||
ID: id,
|
||||
Public: public,
|
||||
Private: private,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,11 +15,11 @@ func DefaultKeyFunc(key Key, deprecatedKeys map[string]Key) jwt.Keyfunc {
|
||||
} else if kidString, ok := kid.(string); !ok {
|
||||
return nil, errors.New("invalid key identifier type")
|
||||
} else if oldKey, ok := deprecatedKeys[kidString]; ok {
|
||||
return oldKey.public, nil
|
||||
} else if kidString == key.id {
|
||||
return key.public, nil
|
||||
return oldKey.Public, nil
|
||||
} else if kidString == key.ID {
|
||||
return key.Public, nil
|
||||
} 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