def decorator(*args, **kwargs): token = _jwt.request_callback() try: payload = _jwt.jwt_decode_callback(token) except jwt.exceptions.DecodeError: pass else: _request_ctx_stack.top.current_identity = _jwt.identity_callback(payload) return fn(*args, **kwargs)
def on_connect(auth): print("[SOCKET] client connected") token = auth.get("token") try: if token is None: raise payload = _jwt.jwt_decode_callback(token) except: emit("dis") print("[SOCKET] client disconected (wrong token)") return False else: print("[SOCKET] client authorize")
def push_to_ctx(): from flask_jwt import _jwt from flask import _request_ctx_stack import jwt token = _jwt.request_callback() try: payload = _jwt.jwt_decode_callback(token) except jwt.exceptions.DecodeError: pass else: _request_ctx_stack.top.current_identity = _jwt.identity_callback( payload)
def wraps(*args, **kwargs): token = _jwt.request_callback() payload = _jwt.jwt_decode_callback(token) # {u'iat': 1551167595, u'exp': 1637567595, u'nbf': 1551167595, u'identity': u'super'} # print 'user is %s, user roletype is %s'%(identity(payload).username,identity(payload).id) method = request.method roletype = identity(payload).id if token: if method not in roles_allowed_permission.get(roletype): return jsonify({'message': "This user permission is not permitted for this operation", 'status_code': '401'}) return fun(*args, **kwargs)
def wrapped(*args, **kwargs): token = request.args.get('token') if token is None: disconnect() try: print(token) payload = _jwt.jwt_decode_callback(token) except jwt.InvalidTokenError as e: disconnect() _request_ctx_stack.top.current_identity = identity = _jwt.identity_callback(payload) if identity is None: disconnect() else: return f(*args, **kwargs)
def decorator(*args, **kwargs): token = _jwt.request_callback() if token is None: raise JWTError('Authorization Required', 'Request does not contain an access token', headers={'WWW-Authenticate': 'JWT realm="%s"' % realm}) try: payload = _jwt.jwt_decode_callback(token) except jwt.InvalidTokenError as e: raise JWTError('Invalid token', str(e)) identity = _jwt.identity_callback(payload) if user_type == 'student' and isinstance(identity, Student): return fn(*args, **kwargs) elif user_type == 'teacher' and isinstance(identity, Teacher): return fn(*args, **kwargs) # NOTE - By default JWTError throws 401. We needed 404. Hence status_code=404 raise JWTError('Unauthorized', 'You are unauthorized to request the api or access the resource', status_code=404)