pythonbrowsergetjwtflask-jwt

how to send access token directly through browser


This is my fuction for accepting a HTTP GET request:

class Test2(Resource):
        @jwt_required
        def get(self):
            mailid = request.args.get('mailid', '')
            username = request.args.get('username', '')
            password = request.args.get('password', '')
            print("Mail ID, Username, Password = ")
            print(mailid, username, password)
            return 'Not supported'

I am getting the error "Missing Authorization Header" when I try the following URL:

http://127.0.0.1:5000/test2?mailid=ABC.xyz.com&username=ABC&password=password&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0eXBlIjoiYWNjZXNzIiwiZXhwIjoxNTIzODc0MzAyLCJpYXQiOjE1MjM4NzM0MDIsImZyZXNoIjpmYWxzZSwibmJmIjoxNTIzODczNDAyLCJqdGkiOiI2NzYxNzdmNS05NGE3LTQzYTUtYjVhYy1mMmVlMzhhN2JhOWEiLCJpZGVudGl0eSI6MTIzfQ.iXZ9_qDtTw5_Q2VxEpvv5pYVAaI8M7P_CVy2Ln79eok

Solution

  • If you're using requests, then you can access the headers like so:

    r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
    # this is just an example from http://docs.python-requests.org/en/master/
    headers = r.headers
    

    here headers is a dict and has keys like content-type. Check the documentation for more info.

    From your code it looks like the decorator @jwt_required checks the header for an auth field in the request header - you should look there. If you can edit the question and add the code, you could get more specific help.