Skip to content

Commit 609335d

Browse files
authored
Merge pull request #637 from signal18/caff_dev
jwt-auth-variable
2 parents 89e8c96 + c399b83 commit 609335d

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ type Config struct {
660660
OAuthClientID string `mapstructure:"api-oauth-client-id" toml:"api-oauth-client-id" json:"apiOAuthClientID"`
661661
OAuthClientSecret string `mapstructure:"api-oauth-client-secret" toml:"api-oauth-client-secret" json:"apiOAuthClientSecret"`
662662
CacheStaticMaxAge int `mapstructure:"cache-static-max-age" toml:"cache-static-max-age" json:"-"`
663+
TokenTimeout int `mapstructure:"api-token-timeout" toml:"api-token-timeout" json:"apiTokenTimeout"`
663664
//OAuthRedirectURL string `mapstructure:"api-oauth-redirect-url" toml:"git-url" json:"-"`
664665
// BackupResticStoragePolicy string `mapstructure:"backup-restic-storage-policy" toml:"backup-restic-storage-policy" json:"backupResticStoragePolicy"`
665666
//ProvMode string `mapstructure:"prov-mode" toml:"prov-mode" json:"provMode"` //InitContainer vs API

server/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (repman *ReplicationManager) loginHandler(w http.ResponseWriter, r *http.Re
343343
//set claims
344344
claims["iss"] = "https://api.replication-manager.signal18.io"
345345
claims["iat"] = time.Now().Unix()
346-
claims["exp"] = time.Now().Add(time.Hour * 48).Unix()
346+
claims["exp"] = time.Now().Add(time.Hour * time.Duration(repman.Conf.TokenTimeout)).Unix()
347347
claims["jti"] = "1" // should be user ID(?)
348348
claims["CustomUserInfo"] = struct {
349349
Name string
@@ -355,6 +355,7 @@ func (repman *ReplicationManager) loginHandler(w http.ResponseWriter, r *http.Re
355355
//sk, _ := jwt.ParseRSAPublicKeyFromPEM(signingKey)
356356

357357
tokenString, err := signer.SignedString(sk)
358+
// log.Printf("Token expiration: %d hour\n", repman.Conf.TokenTimeout)
358359

359360
if err != nil {
360361
w.WriteHeader(http.StatusInternalServerError)
@@ -456,7 +457,7 @@ func (repman *ReplicationManager) handlerMuxAuthCallback(w http.ResponseWriter,
456457
//set claims
457458
claims["iss"] = "https://api.replication-manager.signal18.io"
458459
claims["iat"] = time.Now().Unix()
459-
claims["exp"] = time.Now().Add(time.Hour * 48).Unix()
460+
claims["exp"] = time.Now().Add(time.Hour * time.Duration(repman.Conf.TokenTimeout)).Unix()
460461
claims["jti"] = "1" // should be user ID(?)
461462
claims["CustomUserInfo"] = struct {
462463
Name string

server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func (repman *ReplicationManager) SetDefaultFlags(v *viper.Viper) {
211211
}
212212

213213
func (repman *ReplicationManager) AddFlags(flags *pflag.FlagSet, conf *config.Config) {
214+
flags.IntVar(&conf.TokenTimeout, "api-token-timeout", 48, "Timespan of API Token before expired in hour")
214215

215216
if WithDeprecate == "ON" {
216217
// initDeprecated() // not needed used alias in main

0 commit comments

Comments
 (0)