Flask-Security 解决core.py 中 _request_loader 中 token 错误

上官波鸿
2023-12-01
# send CORS headers 2020年9月9日 17:18:03
    @app.after_request
    def after_request(response):
        response.headers.add('Access-Control-Allow-Origin', '*')
        if request.method == 'OPTIONS':
            response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
            headers = request.headers.get('Access-Control-Request-Headers')
            if headers:
                response.headers['Access-Control-Allow-Headers'] = headers
                ##response.headers['Authorization'] = 'xiaominggessdfs3432ds34ds32432cedsad332e23'
        return response

    @app.before_request
    def before_request():
        # print('before_request')
        next_url = request.path  # 获取登录之前的页面路径
        if next_url == "/login":
            # 跳过处理
            pass
        if next_url == "/app/replenish":
            if request.is_json:
                data = request.get_json( silent = True ) or {}
                # print(data)
                import json
                ll = {}
                ll['datas'] = data
                ll['auth_token'] = 'auth_token'
                request._cached_json = list(request._cached_json)
                request._cached_json[True] = ll

#设置跨域问题
    # supports_credentials = app.config.get('SUPPORTS_CREDENTTIALS')
    # CORS(app,supports_credentials=supports_credentials)

venv\Lib\site-packages\flask_security\core.py

 类似资料: