Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetJwtSigningMethod ¶ added in v1.6.8
func GetJwtSigningMethod(cert *tls.Certificate) (jwt.SigningMethod, error)
GetJwtSigningMethod determines the appropriate JWT signing method based on the certificate's public key type and parameters. For ECDSA keys, it selects ES256, ES384, or ES512 based on the curve bit size. For RSA keys, it defaults to RS256. Panics if the certificate has an unsupported key type or ECDSA curve size.
Types ¶
type Signer ¶
type Signer interface {
Generate(jwt.Claims) (string, error)
SigningMethod() jwt.SigningMethod
KeyId() string
}
Signer provides JWT signing capabilities with configurable signing methods and key identification. It abstracts the process of creating signed JWT tokens from claims.
type SignerImpl ¶ added in v0.34.0
type SignerImpl struct {
// contains filtered or unexported fields
}
SignerImpl is the concrete implementation of the Signer interface. It holds the signing method, private key, and key identifier needed for JWT signing.
func New ¶
func New(sm jwt.SigningMethod, key crypto.PrivateKey, keyId string) *SignerImpl
New creates a new SignerImpl with the specified signing method, private key, and key ID. The key ID is used for JWT key identification in multi-key scenarios.
func (*SignerImpl) Generate ¶ added in v0.34.0
func (j *SignerImpl) Generate(claims jwt.Claims) (string, error)
Generate creates a signed JWT token from the provided claims. If a key ID is configured, it adds the 'kid' header to the token. Returns the signed JWT string or an error if signing fails.
func (*SignerImpl) KeyId ¶ added in v0.34.0
func (j *SignerImpl) KeyId() string
KeyId returns the key identifier associated with this signer. This is used in the JWT header 'kid' field for key identification.
func (*SignerImpl) SigningMethod ¶ added in v0.34.0
func (j *SignerImpl) SigningMethod() jwt.SigningMethod
SigningMethod returns the JWT signing method configured for this signer.
type TlsJwtSigner ¶ added in v1.6.8
type TlsJwtSigner struct {
Signer
TlsCerts *tls.Certificate
}
TlsJwtSigner combines a JWT signer with its associated TLS certificate. It wraps a jwtsigner.Signer and stores the certificate that was used to create the signer, enabling JWT signing operations with certificate-based key identification (kid).
func (*TlsJwtSigner) Set ¶ added in v1.6.8
func (c *TlsJwtSigner) Set(cert *tls.Certificate) error
Set configures the TlsJwtSigner with a new TLS certificate. It updates the stored certificate, determines the appropriate JWT signing method based on the certificate's key type, generates a key ID (kid) from the certificate's SHA1 hash, and creates a new JWT signer with these parameters.