There is a REST client that makes HTTP requests to the server. REST client sends a request which contains a header
Authorization=Bearer someValidBase64
Now I have a server application in Python 3.8, Flask 1.1.1, PyJWT==1.7.1.
@app.route(my_rest_end_point)
def get_service_payments():
authorization_header = request.headers.get('Authorization')
# It prints correctly: Bearer someValidBase64
print("Authorization header:\n" + authorization_header)
# Details from that header
user_permissions = jwt.decode(authorization_header)
It fails with
File "/usr/local/lib/python3.7/site-packages/jwt/api_jws.py", line 188, in _load
raise DecodeError('Invalid header padding')
jwt.exceptions.DecodeError: Invalid header padding
What I tried
authorization_header = request.headers.get('Authorization')
print("Authorization header:\n" + authorization_header)
cleared_header = authorization_header[7:]
print("cleared_header:\n" + cleared_header)
user_permissions = jwt.decode(cleared_header)
It will print
Authorization header:
Bearer someValidBase64
cleared_header:
someValidBase64
It fails again because the token itself has structure
someValidBase64.otherValidPart
so there is a dot ..
Beareris not part of the token, you should split the string and take only the token itself to thejwt.decodefunction