2

I try to use flasgger for my simple RESTful API. The API requireds the authentication/authorization and uses the basic authentication to perform any query.

There is really good documentation about Basic Authentication in swagger.io But how can those settings be implemented in flassger? I've tried to used template to set securityDefinitions into swaggler, but the attempt hasn't been successful yet.

UPD. Probably the issue hasn't been resolved yet. Flasgger doesnt support basic auth #103

Dimaf
  • 653
  • 1
  • 11
  • 25

2 Answers2

3

I've resolved the issue of authentication adding the next code:

swagger_template = {
    # Other settings

    'securityDefinitions': {
        'basicAuth': {
            'type': 'basic'
        }
    },

    # Other settings
}

app = Flask(__name__)
Swagger(app, swagger_config, template=swagger_template)
Dimaf
  • 653
  • 1
  • 11
  • 25
  • This brings the secuityDefinition to the json. However, is there any way to get the security globally to all endpoints? Example here: https://github.com/flasgger/flasgger/issues/377 – variable Apr 03 '20 at 14:00
2

Thanks for Dimaf's answer, helped me a lot. Just want to update the new version, in case someone else run into the same problem.

For Swagger 3.0, the config has been updated to the following (this example is for bearer authorization):

swagger_template = {
    "components": {
        "securitySchemes": {
            "BearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "JWT",
                "in": "header",
            }
        }
    }
}