tokencache.go 740 B

12345678910111213141516171819202122232425262728
  1. package models
  2. import (
  3. "time"
  4. "gorm.io/gorm"
  5. )
  6. // TokenCache stores a token and an expiration for the token for a
  7. // service account. This will never be shared over REST, so no need
  8. // to externalize.
  9. type TokenCache struct {
  10. gorm.Model
  11. ServiceAccountID uint `json:"service_account_id"`
  12. Expiry time.Time `json:"expiry,omitempty"`
  13. // ------------------------------------------------------------------
  14. // All fields below this line are encrypted before storage
  15. // ------------------------------------------------------------------
  16. Token string `json:"access_token"`
  17. }
  18. // IsExpired returns true if a token is expired, false otherwise
  19. func (t *TokenCache) IsExpired() bool {
  20. return time.Now().After(t.Expiry)
  21. }