diff --git a/gateway/api.go b/gateway/api.go index 34bc87f1aa2..11fa0594a78 100644 --- a/gateway/api.go +++ b/gateway/api.go @@ -348,6 +348,8 @@ func handleAddOrUpdate(keyName string, r *http.Request, isHashed bool) (interfac } } } + } else { + newSession.DateCreated = time.Now() } // Update our session object (create it) @@ -1189,6 +1191,7 @@ func createKeyHandler(w http.ResponseWriter, r *http.Request) { } newSession.LastUpdated = strconv.Itoa(int(time.Now().Unix())) + newSession.DateCreated = time.Now() if len(newSession.AccessRights) > 0 { // reset API-level limit to nil if any has a zero-value diff --git a/user/session.go b/user/session.go index a9e925b336b..abb2010611e 100644 --- a/user/session.go +++ b/user/session.go @@ -3,6 +3,7 @@ package user import ( "crypto/md5" "fmt" + "time" "github.com/TykTechnologies/tyk/config" logger "github.com/TykTechnologies/tyk/log" @@ -56,6 +57,7 @@ type SessionState struct { Per float64 `json:"per" msg:"per"` ThrottleInterval float64 `json:"throttle_interval" msg:"throttle_interval"` ThrottleRetryLimit int `json:"throttle_retry_limit" msg:"throttle_retry_limit"` + DateCreated time.Time `json:"date_created" msg:"date_created"` Expires int64 `json:"expires" msg:"expires"` QuotaMax int64 `json:"quota_max" msg:"quota_max"` QuotaRenews int64 `json:"quota_renews" msg:"quota_renews"`