This change updates to go-jose v4, which was a new major release. jose.ParseSigned now expects the supported signing algorithms to be passed, on which we previously did our own check. As they use a dedicated type for this, the slice of string needs to be converted. The returned error also need to be handled in a non-standard way in order to stay compatible. For OIDC v4 we should use the jose.SignatureAlgorithm type directly and wrap errors, instead of returned static defined errors. Closes #583
36 lines
709 B
Go
36 lines
709 B
Go
package op
|
|
|
|
import (
|
|
"errors"
|
|
|
|
jose "github.com/go-jose/go-jose/v4"
|
|
)
|
|
|
|
var ErrSignerCreationFailed = errors.New("signer creation failed")
|
|
|
|
type SigningKey interface {
|
|
SignatureAlgorithm() jose.SignatureAlgorithm
|
|
Key() any
|
|
ID() string
|
|
}
|
|
|
|
func SignerFromKey(key SigningKey) (jose.Signer, error) {
|
|
signer, err := jose.NewSigner(jose.SigningKey{
|
|
Algorithm: key.SignatureAlgorithm(),
|
|
Key: &jose.JSONWebKey{
|
|
Key: key.Key(),
|
|
KeyID: key.ID(),
|
|
},
|
|
}, (&jose.SignerOptions{}).WithType("JWT"))
|
|
if err != nil {
|
|
return nil, ErrSignerCreationFailed // TODO: log / wrap error?
|
|
}
|
|
return signer, nil
|
|
}
|
|
|
|
type Key interface {
|
|
ID() string
|
|
Algorithm() jose.SignatureAlgorithm
|
|
Use() string
|
|
Key() any
|
|
}
|