Separate generate and sign methods for raw jwt.Claims

This commit is contained in:
Melon 2022-12-09 12:53:36 +00:00
parent 3312a37264
commit c1712f1c1d
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 10 additions and 1 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -25,7 +25,10 @@ func NewMJwtSigner(issuer string, key *rsa.PrivateKey) Provider {
func (d *defaultMJwtSigner) Issuer() string { return d.issuer } func (d *defaultMJwtSigner) Issuer() string { return d.issuer }
func (d *defaultMJwtSigner) GenerateJwt(sub, id string, dur time.Duration, claims Claims) (string, error) { func (d *defaultMJwtSigner) GenerateJwt(sub, id string, dur time.Duration, claims Claims) (string, error) {
wrapped := wrapClaims[Claims](d, sub, id, dur, claims) return d.SignJwt(wrapClaims[Claims](d, sub, id, dur, claims))
}
func (d *defaultMJwtSigner) SignJwt(wrapped jwt.Claims) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodRS512, wrapped) token := jwt.NewWithClaims(jwt.SigningMethodRS512, wrapped)
return token.SignedString(d.key) return token.SignedString(d.key)
} }