Skip to content

Commit

Permalink
Add function for expiring jwt token
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Nov 7, 2023
1 parent d8f5a64 commit 090f8e8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/nav/models/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ def is_active(self):
now = datetime.now()
return now >= self.activates() and now < self.expires()

def expire(self):
"""Expires the token"""
data = self.data()
data['exp'] = datetime.now().timestamp()
data['nbf'] = datetime.now().timestamp()
self.token = self._encode_token(data)
self.save()

@classmethod
def _encode_token(cls, token_data):
return jwt.encode(
Expand Down

0 comments on commit 090f8e8

Please sign in to comment.