2021-01-24 23:53:28 +01:00
|
|
|
import time
|
|
|
|
import connexion
|
|
|
|
import six
|
|
|
|
from werkzeug.exceptions import Unauthorized
|
|
|
|
from jose import JWTError, jwt
|
|
|
|
import os
|
|
|
|
|
|
|
|
JWT_SECRET = os.environ['JWT_SECRET']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def decode_token(token):
|
|
|
|
try:
|
2021-01-27 11:58:47 +01:00
|
|
|
return jwt.decode(token, JWT_SECRET)
|
2021-01-24 23:53:28 +01:00
|
|
|
except JWTError as e:
|
|
|
|
six.raise_from(Unauthorized, e)
|
|
|
|
|
|
|
|
|
|
|
|
def get_secret(user, token_info) -> str:
|
|
|
|
return '''
|
|
|
|
You are user_id {user} and the secret is 'wbevuec'.
|
|
|
|
Decoded token claims: {token_info}.
|
|
|
|
'''.format(user=user, token_info=token_info)
|
|
|
|
|
|
|
|
|
|
|
|
def _current_timestamp() -> int:
|
|
|
|
return int(time.time())
|
|
|
|
|