42 lines
957 B
Go
42 lines
957 B
Go
package config
|
|
|
|
import "time"
|
|
|
|
type AuthConfig struct {
|
|
jwtTokenExpiresTTL int
|
|
jwtTokenSecret string
|
|
refreshTokenExpiresTTL int
|
|
refreshTokenSecret string
|
|
}
|
|
|
|
type JWT struct {
|
|
secret string
|
|
expireTTL int
|
|
}
|
|
|
|
func (c *AuthConfig) AccessTokenSecret() string {
|
|
return c.jwtTokenSecret
|
|
}
|
|
|
|
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
|
|
}
|