def validate_admin(*args, **kwargs): jwt_data = _decode_jwt_from_request(request_type='access') uid = jwt_data[0]['identity'] admin_email = StoreModel.find_by_id(uid).email if admin_email in ADMINS: return func(*args, **kwargs) abort(401)
def post(self): jwt_data = _decode_jwt_from_request(request_type='access') userresult = OptionalModules.user().logout_tvuser( jwt_data["identity"][0]) if userresult["result"] == 'success': return {'message': 'User logout is success', 'result': 'success'} else: return userresult
def decorator(*args, **kwargs): try: jwt_data = _decode_jwt_from_request(request_type='access') if jwt_data: ctx_stack.top.jwt = jwt_data except JWTExtendedException: pass return fn(*args, **kwargs)
def wrapper(*args, **kwargs): # attempt to grab the jwt from request try: jwt_data = _decode_jwt_from_request(request_type='access') except: jwt_data = None # if the grab worked and the identity key is in the dict then proceed if jwt_data and 'identity' in jwt_data: return view_function(*args, **kwargs) else: return redirect('login', code=302)
def wrapper(*args, **kwargs): jwt_data, jwt_header = _decode_jwt_from_request(request_type='access') if jwt_data['identity']['role'] != 'user': authorized = True else: authorized = False if not authorized: raise NoAuthorizationError("You are not admin") return view_function(*args, **kwargs)
def wrapper(*args, **kwargs): jwt_data = _decode_jwt_from_request(request_type='access') if ACCESS[jwt_data["identity"][1]] >= ACCESS[urole]: isRoleAuthorized = True else: isRoleAuthorized = False if not isRoleAuthorized: raise NoAuthorizationError( "You are not authorized user to access the API") return apifunction(*args, **kwargs)
def get_identity(): """ To be used only if identity for expired tokens is required, otherwise use current_identity from flask_jwt :return: """ token = None try: token, _ = _decode_jwt_from_request('access') except (JWTExtendedException, PyJWTError): token = getattr(ctx_stack.top, 'expired_jwt', None) if token: try: _load_user(token[config.identity_claim_key]) return getattr(ctx_stack.top, 'jwt_user', None) except UserLoadError: pass
def get(self): import pdb pdb.set_trace() current_user = get_jwt_identity() jwt_data = _decode_jwt_from_request(request_type='access') cookies = "" #_decode_jwt_from_request(request_type='cookies') query_string = "" # _decode_jwt_from_request(request_type='query_string') headers = "" #_decode_jwt_from_request(request_type='headers') json = "" #_decode_jwt_from_request(request_type='json') test = verify_jwt_in_request() test2 = verify_jwt_in_request_optional() # test3 = _encode_key_loader() return { 'Welcome': jwt_data, 'verify_jwt_in_request': test, 'verify_jwt_in_request_optional': test2, 'cookies': cookies, 'query_string': query_string, 'headers': headers, 'json': json, 'username': username, 'password': json, } # def custom_validator(view_function): # @wraps(view_function) # def wrapper(*args, **kwargs): # jwt_data = _decode_jwt_from_request(request_type='access') # # Do your custom validation here. # if (True): # authorized = True # else: # authorized = False # if not authorized: # raise NoAuthorizationError("Explanation goes here") # return view_function(*args, **kwargs) # return jwt_required(wrapper)
def validate_store(*args, **kwargs): jwt_data = _decode_jwt_from_request(request_type='access') uid = jwt_data[0]['identity'] if StoreModel.find_by_id(uid): return func(*args, **kwargs) abort(401)