Skip to content

Commit

Permalink
update generate auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
ochom committed Jan 28, 2024
1 parent d35874f commit f91c593
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type authClaims struct {

// GenerateAuthTokens generates both the detailed token and refresh token
// tokenExpiry is optional and defaults to 3 hours for access token and 7 days for refresh token
func GenerateAuthTokens(data map[string]string, tokenExpiry ...time.Duration) (string, string, error) {
func GenerateAuthTokens(data map[string]string, tokenExpiry ...time.Duration) (map[string]string, error) {
accessTokenExpiry := time.Now().Add(time.Hour * 3).Unix() // 3 hours
refreshTokenExpiry := time.Now().Add(time.Hour * 24 * 7).Unix() // 7 days
if len(tokenExpiry) > 0 {
Expand All @@ -35,7 +35,7 @@ func GenerateAuthTokens(data map[string]string, tokenExpiry ...time.Duration) (s

token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(authSecrete))
if err != nil {
return "", "", err
return nil, err
}

claims.StandardClaims = jwt.StandardClaims{
Expand All @@ -45,10 +45,13 @@ func GenerateAuthTokens(data map[string]string, tokenExpiry ...time.Duration) (s

refreshToken, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(authSecrete))
if err != nil {
return "", "", err
return nil, err
}

return token, refreshToken, nil
return map[string]string{
"token": token,
"refreshToken": refreshToken,
}, nil
}

// GetAuthClaims ...
Expand Down

0 comments on commit f91c593

Please sign in to comment.