Add Refresh token

This commit is contained in:
Aditya Siregar
2025-09-20 17:17:00 +07:00
parent 9db3dcb472
commit f85929c575
7 changed files with 100 additions and 24 deletions
+4 -2
View File
@@ -64,8 +64,10 @@ func LoadConfig() *Config {
func (c *Config) Auth() *AuthConfig {
return &AuthConfig{
jwtTokenSecret: c.Jwt.Token.Secret,
jwtTokenExpiresTTL: c.Jwt.Token.ExpiresTTL,
jwtTokenSecret: c.Jwt.Token.Secret,
jwtTokenExpiresTTL: c.Jwt.Token.ExpiresTTL,
refreshTokenSecret: c.Jwt.RefreshToken.Secret,
refreshTokenExpiresTTL: c.Jwt.RefreshToken.ExpiresTTL,
}
}
+21 -2
View File
@@ -3,8 +3,10 @@ package config
import "time"
type AuthConfig struct {
jwtTokenExpiresTTL int
jwtTokenSecret string
jwtTokenExpiresTTL int
jwtTokenSecret string
refreshTokenExpiresTTL int
refreshTokenSecret string
}
type JWT struct {
@@ -20,3 +22,20 @@ func (c *AuthConfig) AccessTokenExpiresDate() time.Time {
duration := time.Duration(c.jwtTokenExpiresTTL)
return time.Now().UTC().Add(time.Minute * duration)
}
func (c *AuthConfig) RefreshTokenSecret() string {
return c.refreshTokenSecret
}
func (c *AuthConfig) RefreshTokenExpiresDate() time.Time {
duration := time.Duration(c.refreshTokenExpiresTTL)
return time.Now().UTC().Add(time.Minute * duration)
}
func (c *AuthConfig) AccessTokenTTL() time.Duration {
return time.Duration(c.jwtTokenExpiresTTL) * time.Minute
}
func (c *AuthConfig) RefreshTokenTTL() time.Duration {
return time.Duration(c.refreshTokenExpiresTTL) * time.Minute
}
+8 -2
View File
@@ -1,8 +1,9 @@
package config
type Jwt struct {
Token Token `mapstructure:"token"`
Customer Customer `mapstructure:"customer"`
Token Token `mapstructure:"token"`
RefreshToken RefreshToken `mapstructure:"refresh_token"`
Customer Customer `mapstructure:"customer"`
}
type Token struct {
@@ -10,6 +11,11 @@ type Token struct {
Secret string `mapstructure:"secret"`
}
type RefreshToken struct {
ExpiresTTL int `mapstructure:"expires-ttl"`
Secret string `mapstructure:"secret"`
}
type Customer struct {
ExpiresTTL int `mapstructure:"expires-ttl"`
Secret string `mapstructure:"secret"`