Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def before_request(self, view):
# get token parameter
token = view.params.get(PARAM_TOKEN)
identity = view.params.get(PARAM_IDENTITY)
if not token:
raise self.__raise_class(view, 'token_invalid', {'error': 'param_missing', 'parameter': PARAM_TOKEN})
if not identity:
raise self.__raise_class(view, 'token_invalid', {'error': 'param_missing', 'parameter': PARAM_IDENTITY})
# check token
try:
self.check(identity, token)
except TokenException as e:
raise self.__raise_class(view, 'token_invalid', {'error': str(e)})
from Crypto.Cipher import AES
from fair.parameter import Str
from fair.plugin import Plugin, NOT_NULL
from fair.utility import get_cls_with_path
class TokenException(Exception):
"""All Token exception's parent class"""
class TokenTimestampInvalid(TokenException):
"""Token timestamp invalid, timestamp must be integer"""
class TokenTimeout(TokenException):
"""Token time out"""
class TokenInvalid(TokenException):
"""Token invalid"""
class TokenKeyInvalid(TokenException):
"""Token key must be 16 bytes long"""
PARAM_TOKEN = 'token'
PARAM_IDENTITY = 'identity'
TOKEN_TIME_OUT = 60 # 1 minute
from fair.utility import get_cls_with_path
class TokenException(Exception):
"""All Token exception's parent class"""
class TokenTimestampInvalid(TokenException):
"""Token timestamp invalid, timestamp must be integer"""
class TokenTimeout(TokenException):
"""Token time out"""
class TokenInvalid(TokenException):
"""Token invalid"""
class TokenKeyInvalid(TokenException):
"""Token key must be 16 bytes long"""
PARAM_TOKEN = 'token'
PARAM_IDENTITY = 'identity'
TOKEN_TIME_OUT = 60 # 1 minute
class Token(Plugin):
"""Token check Plugin.
:cvar function __key_provider: provide token secret key by identity
"""All Token exception's parent class"""
class TokenTimestampInvalid(TokenException):
"""Token timestamp invalid, timestamp must be integer"""
class TokenTimeout(TokenException):
"""Token time out"""
class TokenInvalid(TokenException):
"""Token invalid"""
class TokenKeyInvalid(TokenException):
"""Token key must be 16 bytes long"""
PARAM_TOKEN = 'token'
PARAM_IDENTITY = 'identity'
TOKEN_TIME_OUT = 60 # 1 minute
class Token(Plugin):
"""Token check Plugin.
:cvar function __key_provider: provide token secret key by identity
e.g.:
def key_provider(identity):
\"""Provide token secret key by identity.
import time
import base64
import binascii
from Crypto.Cipher import AES
from fair.parameter import Str
from fair.plugin import Plugin, NOT_NULL
from fair.utility import get_cls_with_path
class TokenException(Exception):
"""All Token exception's parent class"""
class TokenTimestampInvalid(TokenException):
"""Token timestamp invalid, timestamp must be integer"""
class TokenTimeout(TokenException):
"""Token time out"""
class TokenInvalid(TokenException):
"""Token invalid"""
class TokenKeyInvalid(TokenException):
"""Token key must be 16 bytes long"""
PARAM_TOKEN = 'token'