2

I have a blueprint defined in flask init.py

from flask_restplus import Resource, Api
from . import api_blueprint as _bp
api = Api(_bp, prefix="/api")

user_namespace = api.namespace("user", description="APi for User management")

Then I am using namespace:

parser = user_namespace.parser()
parser.add_argument('Authorization', location='headers')

@api.route('/all/')
@api.expect(parser)
class ListAllUsers(Resource):
    @jwt_required
    def get(self):
        pass

so when I click the Try Out button on swagger documentation It generates the CURL URI that has Authrorization header

--header Authorization: jwt_token_entered_in_UI

but not

--header Authorization: Bearer jwt_token_entered_in_UI

which leads to error saying:

InvalidHeaderError: Bad Authorization header. Expected value 'Bearer <JWT>'
Chang Zhao
  • 631
  • 2
  • 8
  • 24
  • Could you please clarify what is your *question*? – vijoc Dec 05 '18 at 05:59
  • 2
    Do you use OpenAPI 2.0 or OpenAPI 3.0 annotations? Bearer authentication [is supported natively](https://stackoverflow.com/a/45471010/113116) in OpenAPI 3.0 using a security scheme with `type: http` + `scheme: bearer`. But in OpenAPI 2.0, you need to enter the "Bearer" prefix manually as part of the token, i.e. enter the token as `Bearer jwt_token_entered_in_UI`. – Helen Dec 05 '18 at 08:07
  • Oh I didnt even knew that, how do I implement OpenAPI 3.0 in flask-restplus ? that would be great – Chang Zhao Dec 05 '18 at 08:53

0 Answers0