Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
¿Cómo autorizar enlaces de interfaz de usuario de swagger usando python?

Tengo la siguiente configuración para swagger en la aplicación del matraz.

 def configure_swagger(app): """ Swagger Configuration for APP """ app.config["SWAGGER"] = {"title": "Swagger-UI", "uiversion": 3} swagger_config = { "headers": [], "specs": [ { "endpoint": "apispec_1", "route": "/apispec_1.json", "rule_filter": lambda rule: True, # all in "model_filter": lambda tag: True, # all in } ], "static_url_path": "/flasgger_static", "swagger_ui": True, "specs_route": "/swagger/", } SWAGGER_TEMPLATE = { "securityDefinitions": {"APIKeyHeader": {"type": "apiKey", "name": "Authorization", "in": "header"}}} swagger = Swagger(app,config=swagger_config, template=SWAGGER_TEMPLATE)

Además, tengo una configuración de configure_hook(app) que antes de enviar a cualquier API realiza una validación de token .

 def configure_hook(app): """ Configure before request hook """ @app.before_request def before_request(): header = request.headers.get('Authorization') token = header.split(" ")[-1] TokenValidation(token).validate_token() return None

En la configuración de la aplicación setup.py , agregué ambas configuraciones si SSO está habilitado.

 def setup_app(app, config=None): if os.getenv('SSO') == "ENABLE": configure_swagger(app) configure_hook(app) return app

En mi chequeo de salud, en el punto final /healtz . Necesito que la interfaz de usuario de Swagger se autorice automáticamente con el token. La función de punto final se da a continuación.

 @api.route("/healtz") @swag_from("Swagger/healtz_new.yml") def healtz(): return_dict = {"App Version": "1.0.0", "Status": "Healthy"} return return_dict

El archivo de healtz.yml :

 summary: "Health Check" description: "Give the info in json" consumes: - "application/json" produces: - "application/json" responses: 405: description: "Invalid input" # use the same name as above security: - APIKeyHeader: [ 'Authorization' ]

Pero cada vez que intento cargar la interfaz de usuario de Swagger llamando a http://0.0.0.0:8086/swagger recibo un error no autorizado, lo mismo cuando llamo a http://0.0.0.0:8086/healtz .

Idealmente, quiero que todos los puntos finales en la interfaz de usuario de Swagger se autoricen mediante programación usando el token pasado en los encabezados. Revisé la documentación e intenté agregar los tokens de portador, pero no funciona.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!