question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bearer auth seems to not work with python codegen

See original GitHub issue

Bug Report Checklist

my spec has this:

components:
  securitySchemes:
    xxx:
      type: http
      scheme: bearer

  responses:
    GenericApiError:
      description: this object is returned in the cases when an API throws an exception
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/JsonSerializedException'

security:
 - xxx: []

after generating the code, i see this in the code:

configuration.py:
    def get_basic_auth_token(self):
        """Gets HTTP basic authentication header (string).

        :return: The token for basic HTTP authentication.
        """
        return urllib3.util.make_headers(
            basic_auth=self.username + ':' + self.password
        ).get('authorization')

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

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

code doesn’t use bearer token in the requests

openapi-generator version
java -jar openapi-generator-cli.jar  version           
5.0.1
OpenAPI declaration file content or url

https://github.com/Telecominfraproject/wlan-cloud-services/blob/master/portal-services/src/main/resources/portal-services-openapi.yaml

Generation Details
java -jar openapi-generator-cli.jar generate -i portal-services-openapi.yaml -g python -o portal_client
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/1577

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
4c74356b41commented, Mar 31, 2021

we decided against modifying the generated code itself, we are just passing extra headers to the calls, that way we can still use the generated code. @AlfredoCubitos

self.api_client = swagger_client.ApiClient(self.configuration)
self.api_client.default_headers['Authorization'] = "Bearer " + self.bearer._access_token
1reaction
AlfredoCubitoscommented, Mar 31, 2021

@4c74356b41 Yes, this is a better solution 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python bearerAuth not generated · Issue #10060 - GitHub
Let me explain: f the auth_settings is created as in my sample, it works. BUT there's a problem, since the get_api_key_with_prefix wants a...
Read more >
openapi - How can I represent 'Authorization: Bearer <token ...
Workaround for me was to put Bearer xxxxxxxx as the key in the UI authorization box. This worked, though the drawback is telling...
Read more >
How to Use Swagger Inspector
If you don't have any authentication, headers, or query parameters to add, ... add the Authorization: Bearer header and ask you for the...
Read more >
Security - First Steps - FastAPI
If it doesn't see an Authorization header, or the value doesn't have a Bearer token, it will respond with a 401 status code...
Read more >
How do I Send a GET Request with Bearer Token ... - ReqBin
Bearer Authentication (also called token authentication) is an HTTP authentication scheme created as part of OAuth 2.0 but is now used on its ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found