@@ -11,12 +11,6 @@ import (
1111
1212const jtiLength = 21
1313
14- type Service interface {
15- GenerateToken (userID string , scopes []string , ttl time.Duration ) (string , error )
16- ParseToken (ctx context.Context , token string ) (* Claims , error )
17- RevokeToken (ctx context.Context , jti string ) error
18- }
19-
2014type service struct {
2115 config Config
2216
@@ -48,17 +42,17 @@ func New(config Config, revoked *RevokedStorage) (Service, error) {
4842 }, nil
4943}
5044
51- func (s * service ) GenerateToken (userID string , scopes []string , ttl time.Duration ) (string , error ) {
45+ func (s * service ) GenerateToken (userID string , scopes []string , ttl time.Duration ) (* TokenInfo , error ) {
5246 if userID == "" {
53- return "" , fmt .Errorf ("%w: user id is required" , ErrInvalidConfig )
47+ return nil , fmt .Errorf ("%w: user id is required" , ErrInvalidConfig )
5448 }
5549
5650 if len (scopes ) == 0 {
57- return "" , fmt .Errorf ("%w: scopes are required" , ErrInvalidConfig )
51+ return nil , fmt .Errorf ("%w: scopes are required" , ErrInvalidConfig )
5852 }
5953
6054 if ttl < 0 {
61- return "" , fmt .Errorf ("%w: ttl must be non-negative" , ErrInvalidConfig )
55+ return nil , fmt .Errorf ("%w: ttl must be non-negative" , ErrInvalidConfig )
6256 }
6357
6458 if ttl == 0 {
@@ -81,10 +75,10 @@ func (s *service) GenerateToken(userID string, scopes []string, ttl time.Duratio
8175 token := jwt .NewWithClaims (jwt .SigningMethodHS256 , claims )
8276 signedToken , err := token .SignedString ([]byte (s .config .Secret ))
8377 if err != nil {
84- return "" , fmt .Errorf ("failed to sign token: %w" , err )
78+ return nil , fmt .Errorf ("failed to sign token: %w" , err )
8579 }
8680
87- return signedToken , nil
81+ return & TokenInfo { ID : claims . ID , AccessToken : signedToken , ExpiresAt : claims . ExpiresAt . Time } , nil
8882}
8983
9084func (s * service ) ParseToken (ctx context.Context , token string ) (* Claims , error ) {
0 commit comments