Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] bearerAuth always type basic #1577

Closed
vmorris opened this issue Nov 30, 2018 · 13 comments
Closed

[python] bearerAuth always type basic #1577

vmorris opened this issue Nov 30, 2018 · 13 comments

Comments

@vmorris
Copy link

vmorris commented Nov 30, 2018

Description

Defining security component like

"components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ]

When I generate a python client, the API configuration code only allows for type: basic.

In configuration.py:

    def auth_settings(self):
        """Gets Auth Settings dict for api client.

        :return: The Auth Settings information dict.
        """
        return {
            'bearerAuth':
                {
                    'type': 'basic',
                    'in': 'header',
                    'key': 'Authorization',
                    'value': self.get_basic_auth_token()
                },

        }
openapi-generator version

3.3.3

@vmorris
Copy link
Author

vmorris commented Nov 30, 2018

Does #1207 address this?

@vmorris
Copy link
Author

vmorris commented Nov 30, 2018

Ideally this would be something like

        return {
            'bearerAuth':
                {
                    'type': 'http',
                    'in': 'header',
                    'key': 'Authorization',
                    'value': 'Bearer ' + self.token
                },

        }

@ybelenko
Copy link
Contributor

Does #1207 address this?

As you may already notice. Nope, referenced PR adds token authentication feature to PHP Slim Server generator only.

@tomplus As new Python committee, can you answer this?

@tomplus
Copy link
Member

tomplus commented Dec 26, 2018

As we can find here /resources/python/configuration.mustache the bearer token will work only if the type equals oauth2.

@vmorris
Copy link
Author

vmorris commented Dec 27, 2018

I'm not real familiar with mustache.. Shouldn't we be able to add another block for type http? Perhaps a default if oauth2 is not set?

@waza-ari
Copy link

waza-ari commented Jan 17, 2019

In my opinion that should be changed, as the OpenApi allows Bearer authentication without OAuth.

I've tested the proposal by vmorris:

Ideally this would be something like

        return {
            'bearerAuth':
                {
                    'type': 'http',
                    'in': 'header',
                    'key': 'Authorization',
                    'value': 'Bearer ' + self.token
                },

        }

Adding this and of course the token attribute does the job quite well. I'm not too familiar with the template syntax, though

davidwcarlson added a commit to davidwcarlson/openapi-generator that referenced this issue Jan 24, 2019
See OpenAPITools#457
Also OpenAPITools#1446 for typescript, OpenAPITools#1577 for python

Specs defined as follows currently generate BasicAuth and send "Authorization: Basic [base64Encode(username + ":" + password)]"
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer

This change will generate an OAuth header, which will send a "Authorization: Bearer [accessToken]"
This is a smaller, less-impactful change than introducing a BearerAuth object, but this change doesn't support scheme values other than bearer
See also OpenAPITools#1930
davidwcarlson added a commit to davidwcarlson/openapi-generator that referenced this issue Jan 24, 2019
See OpenAPITools#457
Also OpenAPITools#1446 for typescript, OpenAPITools#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools@80ca67c

This PR is an alternative to OpenAPITools#1972
@wing328
Copy link
Member

wing328 commented Jan 29, 2019

Hi all, I've filed #1999 to add the Bearer authentication support to the Python client. Please review when you've time.

@wing328
Copy link
Member

wing328 commented Jan 30, 2019

#1999 merged into master. Please try the latest master (snapshot, docker image, etc).

Closing this for the time being.

@wing328 wing328 closed this as completed Jan 30, 2019
wing328 pushed a commit that referenced this issue Feb 9, 2019
* fix #457 by introducing an HttpBearerAuth object

See #457
Also #1446 for typescript, #1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of 80ca67c

This PR is an alternative to #1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this issue Feb 27, 2019
* fix OpenAPITools#457 by introducing an HttpBearerAuth object

See OpenAPITools#457
Also OpenAPITools#1446 for typescript, OpenAPITools#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools@80ca67c

This PR is an alternative to OpenAPITools#1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
@waza-ari
Copy link

@wing328 sorry it took some time for me to come back to that project. I was testing it today using the current master snapshot docker image and it works perfectly. Thanks for your work!

@esseti
Copy link

esseti commented Feb 24, 2020

is this fix released in 3.X version? in my generated code there's no bearerAuth in the auth_setting(self) it should have something like this (note: what should be the identifier ?)

    'bearerAuth':
                {
                    'type': 'http',
                    'in': 'header',
                    'key': 'Authorization',
                    'value': self.get_api_key_with_prefix('<THEPREFIX>')
                },

@vmorris
Copy link
Author

vmorris commented Feb 24, 2020

@esseti this went into the 4.0.0 milestone

@4c74356b41
Copy link

hey, i'm looking at a code generated for python and i see this:

    def auth_settings(self):
        """Gets Auth Settings dict for api client.

        :return: The Auth Settings information dict.
        """
        return {
        }

openapi spec has bearer token auth on all requests pretty much
should I raise a new issue @vmorris ?

@vmorris
Copy link
Author

vmorris commented Mar 1, 2021

should I raise a new issue @vmorris ?

@4c74356b41 I am not an expert on this group's preferred way to handle this, but I think you should open a new issue and reference this one.

therve pushed a commit to DataDog/datadog-api-client-java that referenced this issue Mar 23, 2021
* fix #457 by introducing an HttpBearerAuth object

See OpenAPITools/openapi-generator#457
Also OpenAPITools/openapi-generator#1446 for typescript, OpenAPITools/openapi-generator#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools/openapi-generator@80ca67c

This PR is an alternative to OpenAPITools/openapi-generator#1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
api-clients-generation-pipeline bot pushed a commit to DataDog/datadog-api-client-java that referenced this issue Sep 8, 2021
* fix #457 by introducing an HttpBearerAuth object

See OpenAPITools/openapi-generator#457
Also OpenAPITools/openapi-generator#1446 for typescript, OpenAPITools/openapi-generator#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools/openapi-generator@80ca67c

This PR is an alternative to OpenAPITools/openapi-generator#1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants