I am building an API with flask_restplus
and flask_httpauth
for token based authentication. Everything is working nicely, except for one thing. In the Swagger UI, I get error 401 when I try to execute a search query. Adding "Bearer" to the authorization does not help. Please see the screenshot below.
The funny thing is, copy & pasting the output from curl
(in the Swagger UI) and running it from the terminal does return the correct output. Same with running it in Postman. The problem is probably within the Swagger UI. Any suggestions?
The suggestion on Github is unfortunately not working for me.
NB: it seems like verify_token(token)
is not receiving input from the Swagger UI. When I try to print token
, it is empty when being called from Swagger, but shows the value when being called from curl/Postman.
Part of the code:
authorizations = {
'Bearer Auth': {
'type': 'apiKey',
'in': 'header',
'name': 'Authorization'
},
}
api = Api(blueprint, version='1.0', title='Flask API',
description='My API', security='Bearer Auth', authorizations=authorizations)
@token_auth.verify_token
def verify_token(token):
g.current_user = User.check_token(token) if token else None
return g.current_user is not None