generated from VLADIMIR/template
update refresh
This commit is contained in:
@@ -5,15 +5,16 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type processor struct {
|
||||
secret string
|
||||
secret []byte
|
||||
}
|
||||
|
||||
func NewProcessor(secret string) IProcessorJWT {
|
||||
return &processor{
|
||||
secret: secret,
|
||||
secret: []byte(secret),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +33,7 @@ func (p *processor) GenerateAccessToken(userId int, userEmail string, userRoles
|
||||
}
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return token.SignedString([]byte(p.secret))
|
||||
return token.SignedString(p.secret)
|
||||
}
|
||||
|
||||
func (p *processor) GenerateRefreshToken(userId int) (string, error) {
|
||||
@@ -44,11 +45,12 @@ func (p *processor) GenerateRefreshToken(userId int) (string, error) {
|
||||
ExpiresAt: jwt.NewNumericDate(now.Add(7 * 24 * time.Hour)),
|
||||
IssuedAt: jwt.NewNumericDate(now),
|
||||
NotBefore: jwt.NewNumericDate(now),
|
||||
ID: uuid.New().String(),
|
||||
},
|
||||
}
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return token.SignedString([]byte(p.secret))
|
||||
return token.SignedString(p.secret)
|
||||
}
|
||||
|
||||
func (p *processor) GetClaims(token string) (*JWTClaims, error) {
|
||||
|
||||
Reference in New Issue
Block a user