Coder Social home page Coder Social logo

Comments (2)

uniqueg avatar uniqueg commented on August 16, 2024

The problem is that there are no securitySchemes defined in the (pro)TES specification, neither are they applied globally or to individual operations (see steps 1 and 2 here: https://swagger.io/docs/specification/authentication/)

Now, ideally we should be able to add these through the app config via FOCA. So, e.g., by specifying the following API configuration, we should get what we need:

api:
  specs:
    - path:
        - api/9e9c5aa.task_execution_service.openapi.yaml
        - api/additional_logs.yaml
      add_operation_fields:
        x-openapi-router-controller: ga4gh.tes.server
        security:
          - bearerAuth: []
      add_security_fields:
        bearerAuth:
          type: http
          scheme: bearer
          bearerFormat: JWT
          x-bearerInfoFunc: foca.security.auth.validate_token

However, we can currently only add fields to existing operations and security definitions. Therefore, add the security properties to each operation works well with the above example, but adding securitySchemes when there isn't already one defined, does not work with the current implementation in FOCA (link to code):

        if not spec.disable_auth and spec.add_security_fields is not None:
            for key, val in spec.add_security_fields.items():
                # OpenAPI 2
                sec_defs = spec_parsed.get('securityDefinitions', {})
                for sec_def in sec_defs.values():
                    sec_def[key] = val
                # OpenAPI 3
                sec_schemes = spec_parsed.get(
                    'components', {'securitySchemes': {}}
                ).get('securitySchemes', {})  # type: ignore
                for sec_scheme in sec_schemes.values():
                    sec_scheme[key] = val
            logger.debug(f"Added security fields: {spec.add_security_fields}")

Therefore, without changing the implementation in FOCA, we need to add an additional, partial OpenAPI file, e.g., api/security_schemes.yaml, with the following content:

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

And then use the following FOCA API configuration:

api:
  specs:
    - path:
        - api/9e9c5aa.task_execution_service.openapi.yaml
        - api/additional_logs.yaml
        - api/security_schemes.yaml
      add_operation_fields:
        x-openapi-router-controller: ga4gh.tes.server
        security:
          - bearerAuth: []
      add_security_fields:
        x-bearerInfoFunc: foca.security.auth.validate_token

I suggest that we commit the api/security_schemes.yaml file and configuration changes to version control. I will raise a PR.

from protes.

uniqueg avatar uniqueg commented on August 16, 2024

Closed by #163

from protes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.