Skip to content

Commit

Permalink
Store token's time of creation (TykTechnologies#2388)
Browse files Browse the repository at this point in the history
Added new field `date_created` in SessionState
  • Loading branch information
komalsukhani authored and buger committed Jul 10, 2019
1 parent 96f02ac commit 3015c87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gateway/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions user/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package user
import (
"crypto/md5"
"fmt"
"time"

"github.com/TykTechnologies/tyk/config"
logger "github.com/TykTechnologies/tyk/log"
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit 3015c87

Please sign in to comment.