2023-06-18 13:03:41 +01:00
|
|
|
package mjwt
|
|
|
|
|
|
|
|
import (
|
2023-10-25 17:37:55 +01:00
|
|
|
"crypto/rsa"
|
2023-06-18 13:03:41 +01:00
|
|
|
"github.com/golang-jwt/jwt/v4"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Signer is used to generate MJWT tokens.
|
|
|
|
// Signer can also be used as a Verifier.
|
|
|
|
type Signer interface {
|
|
|
|
Verifier
|
2023-06-20 00:32:16 +01:00
|
|
|
GenerateJwt(sub, id string, aud jwt.ClaimStrings, dur time.Duration, claims Claims) (string, error)
|
2023-06-18 13:03:41 +01:00
|
|
|
SignJwt(claims jwt.Claims) (string, error)
|
2024-06-09 16:49:57 +01:00
|
|
|
GenerateJwtWithKID(sub, id string, aud jwt.ClaimStrings, dur time.Duration, claims Claims, kID string) (string, error)
|
|
|
|
SignJwtWithKID(claims jwt.Claims, kID string) (string, error)
|
2023-06-18 13:03:41 +01:00
|
|
|
Issuer() string
|
2023-10-25 17:37:55 +01:00
|
|
|
PrivateKey() *rsa.PrivateKey
|
2024-06-09 16:49:57 +01:00
|
|
|
PrivateKeyOf(kID string) *rsa.PrivateKey
|
2023-06-18 13:03:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verifier is used to verify the validity MJWT tokens and extract the claim values.
|
|
|
|
type Verifier interface {
|
|
|
|
VerifyJwt(token string, claims baseTypeClaim) (*jwt.Token, error)
|
2023-10-25 17:37:55 +01:00
|
|
|
PublicKey() *rsa.PublicKey
|
2024-06-09 16:49:57 +01:00
|
|
|
PublicKeyOf(kID string) *rsa.PublicKey
|
|
|
|
GetKeyStore() KeyStore
|
2023-06-18 13:03:41 +01:00
|
|
|
}
|
2024-06-08 15:02:49 +01:00
|
|
|
|
|
|
|
// KeyStore is used for the kid header support in Signer and Verifier.
|
|
|
|
type KeyStore interface {
|
2024-06-09 16:49:57 +01:00
|
|
|
SetKey(kID string, prvKey *rsa.PrivateKey)
|
|
|
|
SetKeyPublic(kID string, pubKey *rsa.PublicKey)
|
2024-06-09 00:49:27 +01:00
|
|
|
RemoveKey(kID string)
|
2024-06-08 15:02:49 +01:00
|
|
|
ListKeys() []string
|
|
|
|
GetKey(kID string) *rsa.PrivateKey
|
|
|
|
GetKeyPublic(kID string) *rsa.PublicKey
|
|
|
|
ClearKeys()
|
|
|
|
}
|