diff --git a/interfaces.go b/interfaces.go index f0ca8c5..939a466 100644 --- a/interfaces.go +++ b/interfaces.go @@ -1,6 +1,7 @@ package mjwt import ( + "crypto/rsa" "github.com/golang-jwt/jwt/v4" "time" ) @@ -12,9 +13,11 @@ type Signer interface { GenerateJwt(sub, id string, aud jwt.ClaimStrings, dur time.Duration, claims Claims) (string, error) SignJwt(claims jwt.Claims) (string, error) Issuer() string + PrivateKey() *rsa.PrivateKey } // 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) + PublicKey() *rsa.PublicKey } diff --git a/signer.go b/signer.go index 99f6631..b44ca79 100644 --- a/signer.go +++ b/signer.go @@ -18,6 +18,7 @@ type defaultMJwtSigner struct { } var _ Signer = &defaultMJwtSigner{} +var _ Verifier = &defaultMJwtSigner{} // NewMJwtSigner creates a new defaultMJwtSigner using the issuer name and rsa.PrivateKey func NewMJwtSigner(issuer string, key *rsa.PrivateKey) Signer { @@ -73,6 +74,9 @@ func (d *defaultMJwtSigner) VerifyJwt(token string, claims baseTypeClaim) (*jwt. return d.verify.VerifyJwt(token, claims) } +func (d *defaultMJwtSigner) PrivateKey() *rsa.PrivateKey { return d.key } +func (d *defaultMJwtSigner) PublicKey() *rsa.PublicKey { return d.verify.pub } + // readOrCreatePrivateKey returns the private key it the file already exists, // generates a new private key and saves it to the file, or returns an error if // reading or generating failed. diff --git a/verifier.go b/verifier.go index a0ef2b2..0fe9411 100644 --- a/verifier.go +++ b/verifier.go @@ -57,3 +57,5 @@ func (d *defaultMJwtVerifier) VerifyJwt(token string, claims baseTypeClaim) (*jw } return withClaims, claims.Valid() } + +func (d *defaultMJwtVerifier) PublicKey() *rsa.PublicKey { return d.pub }