summaryrefslogtreecommitdiff
path: root/websockify/token_plugins.py
diff options
context:
space:
mode:
authorJavier Prieto <jprietove@gmail.com>2021-01-27 15:16:08 +0100
committerJavier Prieto <jprietove@gmail.com>2021-01-27 15:16:08 +0100
commite9367b03be14bfad70db36106a3de081b3f0ae82 (patch)
tree16ab59ea9db9cd188ca771b724f9993044f17fbe /websockify/token_plugins.py
parentadc278657a9bb36514b15a80bb255f6878bbacbe (diff)
downloadwebsockify-e9367b03be14bfad70db36106a3de081b3f0ae82.tar.gz
Added exp claim for JWT token
Diffstat (limited to 'websockify/token_plugins.py')
-rw-r--r--websockify/token_plugins.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/websockify/token_plugins.py b/websockify/token_plugins.py
index e03839a..80a9568 100644
--- a/websockify/token_plugins.py
+++ b/websockify/token_plugins.py
@@ -1,5 +1,6 @@
import os
import sys
+import time
class BasePlugin():
def __init__(self, src):
@@ -127,6 +128,12 @@ class JWTTokenApi(BasePlugin):
token = jwt.JWT(key=key, jwt=token.claims)
parsed = json.loads(token.claims)
+
+ if 'exp' in parsed:
+ # Expiration time is present, so we need to check it
+ if time.time() > parsed['exp']:
+ print('Token has expired!', file=sys.stderr)
+ return None
return (parsed['host'], parsed['port'])
except Exception as e: