Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

[BUG] Can't use multiple security schemes / disable them #180

@commentator8

Description

@commentator8

Bug Report Checklist

  • [v] Have you provided a full/minimal spec to reproduce the issue?
  • [v] Have you validated the input using an OpenAPI validator (example)?
  • [v] Have you tested with the latest master to confirm the issue still exists?
  • [v] Have you searched for related issues/PRs?
  • [-] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request
Description

I initially encountered something very much like this, where when using the main openapi-generator I did not get attributes generated for my response (the attributes are required and with normal names e.g. password). I checked swagger-codegen and it worked fine, and I checked this repo's version and it worked also. I much prefer this version or openapi-generator as they have type hints and client side validation.

When trying to use this version (as the successor to openapi-generator) I encountered a couple of issues. I make use of two security headers ob_user_auth (passed as Authentication) and ob_m2m_auth (passed as User-Authentication). As far as I can tell the code doesn't allow for more than 1.

security_requirement_object = self.api_client.configuration.get_security_requirement_object(
    'paths/' + path + '/get/security',
    _security,
    security_index
)

where this code returns a specific security_requirement_object based on an index and security_index_info defaults to

self.security_index_info: SecurityIndexInfo = security_index_info or {'security': 0}

and even if i manually populated it (couldn't see how to easily) it returns an index and as such returns just the one APIToken possibility.

Furthermore, as opposed to the old version, I can't see how to disable the security headers without resorting to something like this:

security_scheme_info: api_configuration.SecuritySchemeInfo = {
    "ob_user_auth": ApiKeySecurityScheme('', '', in_location='fake'),
    "ob_m2m_auth": ApiKeySecurityScheme('', '', in_location='fake'),
}

used_configuration = api_configuration.ApiConfiguration(
    security_scheme_info=security_scheme_info,
)

since security_scheme_instance.apply_auth can't take a dict and there isn't a check for the headers not being set or any other disable method that I can see. This works because if in_location is not one of the if/elif it knows about it ignores it. Am i missing anything?

when i configure with security_scheme_info: api_configuration.SecuritySchemeInfo = {} i get this (only one header is sent):

send: b'GET /api/v1/basic/1ff033ca-bb4b-4b74-b45e-c34b1b2301ec?account_id=1ece138f-4fb0-4f8e-8256-a7edda655c04 HTTP/1.1\r\nHost: localhost:8004\r\nAccept-Encoding: identity\r\nUser-Agent: OpenAPI-JSON-Schema-Generator/1.0.0/python\r\nUser-Authorization: sampleApiKeyValue\r\nAccept: application/json\r\n\r\n'

In the old repo however if I configure it as follows:

configuration.api_key['ob_m2m_auth'] = 'm2m'

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
configuration.api_key_prefix['ob_m2m_auth'] = 'Bearer'

# Configure API key authorization: ob_user_auth
configuration.api_key['ob_user_auth'] = 'user'

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
configuration.api_key_prefix['ob_user_auth'] = 'Bearer'

it sends this

send: b'GET /api/v1/basic/1ff033ca-bb4b-4b74-b45e-c34b1b2301ec?account_id=1ece138f-4fb0-4f8e-8256-a7edda655c04 HTTP/1.1\r\nHost: localhost:8004\r\nAccept-Encoding: identity\r\nUser-Agent: OpenAPI-Generator/1.0.0/python\r\nAuthorization: Bearer m2m\r\nUser-Authorization: Bearer user\r\nAccept: application/json\r\n\r\n'

which is valid. And if I comment out those config lines it sends nothing - which is exactly what I need for dev environments.

Since the code changes between the repos are significant and you explicitly changed how you manage the security headers - I'm not sure if it is possible still. It might be easier to backport the fix from the issue i referenced above to the old repo for the meanwhile.

TLDR - i would like either to get the attributes working in the old repo or get the security controls able to be a) disabled on demand and b) send multiple auth headers. Is any of that possible?

Here is the script used to test, i could mock up a server if needed to test.

Thanks!

openapi-json-schema-generator version

Using the docker current version - couldn't easily get the internal version.

OpenAPI declaration file content or url

Gist

Generation Details
docker run --rm -v "${PWD}:/local" openapijsonschematools/openapi-json-schema-generator-cli generate \  
    -i /local/openapi.yaml \
    -g python \
    -o /local/token_client_new_openapi
Steps to reproduce

generate with the above gsit and use the following to send a request.

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions