Я сделал следующий декоратор в колбе для защиты моего API:
def auth_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if session.get('user') is None:
if 'Authorization' not in request.headers:
return jsonify({'status': 0,'message':'Unauthorized'})
else:
try:
token = request.headers.get('Authorization')
data = jwt.decode(token.split(" ")[1], app.config['SECRET_KEY'],algorithms=['HS256'])
return f(*args, **kwargs)
except Exception as e:
print(str(e))
return jsonify({'status': 0,'message':'Unauthorized'})
else:
return f(*args, **kwargs)
return decorated_function
Это прекрасно работает, когда он используется в Интернете, когда используются сессии, а не JWT, но когда я использую cURL, например:
curl -i -H "Content-Type: application/json" -H "Authorization: Bearer mytoken123" -X POST -d '{"phone":"myphonenumber","type":"send"}' http://localhost:5000/api/OTP
Я получаю следующий ответ:
400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
127.0.0.1 - - [25/Dec/2018 14:00:30] "POST /api/OTP HTTP/1.1" 200 -
Что здесь происходит?