Browse Source

Fixes #1021: Corrected evaluation of API token expiration time

Jeremy Stretch 8 years ago
parent
commit
1c38f705a7
2 changed files with 4 additions and 4 deletions
  1. 3 3
      netbox/users/models.py
  2. 1 1
      netbox/utilities/api.py

+ 3 - 3
netbox/users/models.py

@@ -39,6 +39,6 @@ class Token(models.Model):
 
 
     @property
     @property
     def is_expired(self):
     def is_expired(self):
-        if self.expires is not None and timezone.now() > self.expires:
-            return True
-        return False
+        if self.expires is None or timezone.now() < self.expires:
+            return False
+        return True

+ 1 - 1
netbox/utilities/api.py

@@ -30,7 +30,7 @@ class TokenAuthentication(authentication.TokenAuthentication):
             raise exceptions.AuthenticationFailed("Invalid token")
             raise exceptions.AuthenticationFailed("Invalid token")
 
 
         # Enforce the Token's expiration time, if one has been set.
         # Enforce the Token's expiration time, if one has been set.
-        if token.expires and not token.is_expired:
+        if token.is_expired:
             raise exceptions.AuthenticationFailed("Token expired")
             raise exceptions.AuthenticationFailed("Token expired")
 
 
         if not token.user.is_active:
         if not token.user.is_active: